facet.selection.ParameterSpace#
- class facet.selection.ParameterSpace(estimator, name=None)[source]#
A set of parameter choices or distributions spanning a parameter space for optimizing the hyperparameters of a single estimator.
Parameter spaces provide an easy approach to define and validate search spaces for hyperparameter tuning of ML pipelines using scikit-learn’s
GridSearchCV
andRandomizedSearchCV
.Parameter choices (as lists) or distributions (from
scipy.stats
) can be set using attribute access, and will be validated for correct names and values.Example:
ps = ParameterSpace( RegressorPipelineDF( regressor=RandomForestRegressorDF(random_state=42), preprocessing=simple_preprocessor, ), name="random forest", ) ps.regressor.min_weight_fraction_leaf = scipy.stats.loguniform(0.01, 0.1) ps.regressor.max_depth = [3, 4, 5, 7, 10] cv = RandomizedSearchCV( estimator=ps.estimator, param_distributions=ps.parameters, # ... ) # The following will raise an AttributeError for the unknown attribute xyz: ps.regressor.xyz = [3, 4, 5, 7, 10] # the following will raise a TypeError because we do not assign a list or distribution: ps.regressor.max_depth = 3
- Bases
BaseParameterSpace
[+T_Estimator_co]- Generic types
+T_Estimator_co(bound=
EstimatorDF
, __covariant__=True)- Metaclasses
- Parameters
estimator (
ParameterSpace
) – the estimator to which to apply the parametersname (
Optional
[str
]) – a name for the estimator to be used in summary reports; defaults to the name of the estimator’s class, or the name of the final estimator’s class if argestimator
is a pipeline
Method summary
Get the name for this parameter space's estimator.
Generate a dictionary of parameter choices and distributions, compatible with scikit-learn's CV search API (e.g.,
GridSearchCV
orRandomizedSearchCV
).Render this object as an expression.
Attribute summary
The estimator associated with this parameter space.
The parameter choices (as lists) or distributions (from
scipy.stats
) that constitute this parameter space.Definitions
- get_name()[source]#
Get the name for this parameter space’s estimator.
If no name was passed to the constructor, determine the default name recursively as follows:
for meta-estimators, this is the default name of the delegate estimator
for pipelines, this is the default name of the final estimator
for all other estimators, this is the name of the estimator’s class
- Return type
- Returns
the name for this parameter space’s estimator
- get_parameters(prefix=None)[source]#
Generate a dictionary of parameter choices and distributions, compatible with scikit-learn’s CV search API (e.g.,
GridSearchCV
orRandomizedSearchCV
).- Parameters
prefix (
Optional
[str
]) – an optional prefix to prepend to all parameter names in the resulting dictionary, separated by two underscore characters (__
) as per scikit-learn’s convention for hierarchical parameter names- Return type
Dict
[str
,Union
[List
[Any
],rv_continuous
,rv_discrete
]]- Returns
a dictionary mapping parameter names to parameter choices (as lists) or distributions (from
scipy.stats
)
- to_expression()[source]#
Render this object as an expression.
- Return type
- Returns
the expression representing this object
- property estimator: base.T_Estimator#
The estimator associated with this parameter space.
- Return type
TypeVar
(T_Estimator
, bound=EstimatorDF
, covariant=True)
- property parameters: Union[List[Dict[str, Union[List[Any], scipy.stats.rv_continuous, scipy.stats.rv_discrete]]], Dict[str, Union[List[Any], scipy.stats.rv_continuous, scipy.stats.rv_discrete]]]#
The parameter choices (as lists) or distributions (from
scipy.stats
) that constitute this parameter space.This is a shortcut for calling method
get_parameters()
with no arguments.- Return type
Union
[List
[Dict
[str
,Union
[List
[Any
],rv_continuous
,rv_discrete
]]],Dict
[str
,Union
[List
[Any
],rv_continuous
,rv_discrete
]]]