secure_learning.models.grid_cv module
Module for Cross Validation (CV) following the GridSearchCV paradigm of sklearn.
- class secure_learning.models.grid_cv.GridCV(model_type, parameter_collection, X, y, random_state=None, shuffle=False)[source]
Bases:
object
Exhaustive search over specified parameter values for a model.
- __init__(model_type, parameter_collection, X, y, random_state=None, shuffle=False)[source]
Constructor method.
- Parameters:
model_type (
TypeVar
(ModelTypeTV
, bound=Type
[Model
])) – Model type (class)parameter_collection (
ParameterCollection
) – Parameters to use for cross validationX (
List
[List
[SecureFixedPoint
]]) – Secret-shared training datay (
List
[SecureFixedPoint
]) – Secret-shared target vector
- Raises:
AttributeError – if the parameters contain an unknown key
- best_param_set()[source]
Return parameter set with the best score result.
- Return type:
Tuple
[float
,Parameters
]- Returns:
parameter set with the best score result
- async cross_validation(folds)[source]
Compute cross validation over all given combinations of parameters and return the score for each set.
- Parameters:
folds (
Union
[int
,List
[Tuple
[List
[int
],List
[int
]]]]) – Folding sets. If set to \(k\) (integer) then a KFold (from sklearn.model_selection) is used. If it is not set then KFold is called with \(k=5\). It also possible to pass custom folds as a list of tuples of train and test indexes: e.g. \([([2, 3], [0, 1, 4]), ([0, 1, 3], [2, 4]), ([0, 1, 2], [3, 4])]\) is a three-fold of an array of five elements \(([2, 3], [0, 1, 4])\) -> 1st fold, elements with indexes \([2, 3]\) are used in the train set, while elements with indexes \([0, 1, 4]\) are used in the test set \(([0, 1, 3], [2, 4])\) -> 2nd fold, elements with indexes \([0, 1, 3]\) are used in the train set, while elements with indexes \([2, 4]\) are used in the test set \(([0, 1, 2], [3, 4])\) -> 3rd fold, elements with indexes \([0, 1, 2]\) are used in the train set, while elements with indexes \([3, 4]\) are used in the test set- Return type:
List
[List
[float
]]- Returns:
A list containing one list of score results (over different folds) for each parameters combination
- property results: List[List[float]]
The results of grid cross-validation
- Returns:
Results of grid cross-validation
- Raises:
ValueError – Raised when results are not available
- sorted_param_set()[source]
Return a sorted list of the parameter sets with their score results
- Return type:
List
[Tuple
[float
,Parameters
]]- Returns:
sorted list of the parameter sets with their score results
- class secure_learning.models.grid_cv.ParameterCollection(solver_type, penalty, alpha, tolerance, minibatch_size, coef_init, nr_maxiters, class_weights=<factory>, print_progress=<factory>, secure_permutations=<factory>, exponentiation=<factory>, eta0=<factory>)[source]
Bases:
object
A collection of parameters, serves as a helper class for generation of a parameter grid.
-
alpha:
List
[float
]
-
class_weights:
List
[ClassWeightsTypes
]
-
coef_init:
List
[Optional
[List
[SecureFixedPoint
]]]
-
eta0:
List
[Optional
[float
]]
-
exponentiation:
List
[ExponentiationTypes
]
-
minibatch_size:
List
[Optional
[int
]]
-
nr_maxiters:
List
[int
]
-
penalty:
List
[PenaltyTypes
]
-
print_progress:
List
[bool
]
-
secure_permutations:
List
[bool
]
-
solver_type:
List
[SolverTypes
]
-
tolerance:
List
[float
]
-
alpha:
- class secure_learning.models.grid_cv.Parameters(solver_type, penalty, alpha, tolerance, minibatch_size, coef_init, nr_maxiters, class_weights, print_progress, secure_permutations, exponentiation, eta0)[source]
Bases:
object
Helper class, used internally, to provide a set a parameters.
-
alpha:
float
-
class_weights:
ClassWeightsTypes
-
coef_init:
Optional
[List
[SecureFixedPoint
]]
-
eta0:
Optional
[float
]
-
exponentiation:
ExponentiationTypes
-
minibatch_size:
Optional
[int
]
-
nr_maxiters:
int
-
penalty:
PenaltyTypes
-
print_progress:
bool
-
secure_permutations:
bool
-
solver_type:
SolverTypes
-
tolerance:
float
-
alpha: