lale.lib.lale.smac module¶
- class lale.lib.lale.smac.SMAC(*, estimator=None, scoring, best_score=0.0, cv=5, handle_cv_failure=False, max_evals=50, max_opt_time=None, lale_num_grids=None)¶
Bases:
PlannedIndividualOp
SMAC, the optimizer used inside auto-weka and auto-sklearn.
This documentation is auto-generated from JSON schemas.
Examples
>>> from sklearn.metrics import make_scorer, f1_score, accuracy_score >>> lr = LogisticRegression() >>> clf = SMAC(estimator=lr, scoring='accuracy', cv=5) >>> from sklearn import datasets >>> diabetes = datasets.load_diabetes() >>> X = diabetes.data[:150] >>> y = diabetes.target[:150] >>> trained = clf.fit(X, y) >>> predictions = trained.predict(X)
Other scoring metrics:
>>> clf = SMAC(estimator=lr, scoring=make_scorer(f1_score, average='macro'), cv=3, max_evals=2)
- Parameters
estimator (union type, default None) –
Planned Lale individual operator or pipeline.
operator
or None
lale.lib.sklearn.LogisticRegression
scoring (union type, optional, not for optimizer) –
Scorer object, or known scorer named by string.
None
When not specified, use accuracy for classification tasks and r2 for regression.
or union type
Scorer object, or known scorer named by string.
callable
Callable with signature
scoring(estimator, X, y)
as documented in sklearn scoring.The callable has to return a scalar value, such that a higher score is better. This may be created from one of the sklearn metrics using make_scorer. Or it can be one of the scoring callables returned by the factory functions in lale.lib.aif360 metrics, for example,
symmetric_disparate_impact(**fairness_info)
. Or it can be a completely custom user-written Python callable.or ‘accuracy’, ‘explained_variance’, ‘max_error’, ‘roc_auc’, ‘roc_auc_ovr’, ‘roc_auc_ovo’, ‘roc_auc_ovr_weighted’, ‘roc_auc_ovo_weighted’, ‘balanced_accuracy’, ‘average_precision’, ‘neg_log_loss’, or ‘neg_brier_score’
Known scorer for classification task.
or ‘r2’, ‘neg_mean_squared_error’, ‘neg_mean_absolute_error’, ‘neg_root_mean_squared_error’, ‘neg_mean_squared_log_error’, or ‘neg_median_absolute_error’
Known scorer for regression task.
best_score (float, optional, not for optimizer, default 0.0) –
The best score for the specified scorer.
Given that higher scores are better, passing
(best_score - score)
as a loss to the minimizing optimizer will maximize the score. By specifying best_score, the loss can be >=0, where 0 is the best loss.cv (union type, not for optimizer, default 5) –
Cross-validation as integer or as object that has a split function.
The fit method performs cross validation on the input dataset for per trial, and uses the mean cross validation performance for optimization. This behavior is also impacted by the handle_cv_failure flag.
union type
integer, >=2, >=3 for optimizer, <=4 for optimizer, uniform distribution, default 5
Number of folds for cross-validation.
or None, not for optimizer
to use the default 5-fold cross validation
or CrossvalGenerator, not for optimizer
Object with split function: generator yielding (train, test) splits as arrays of indices. Can use any of the iterators from https://scikit-learn.org/stable/modules/cross_validation.html#cross-validation-iterators
handle_cv_failure (boolean, not for optimizer, default False) –
How to deal with cross validation failure for a trial.
If True, continue the trial by doing a 80-20 percent train-validation split of the dataset input to fit and report the score on the validation part. If False, terminate the trial with FAIL status.
max_evals (integer, >=1, not for optimizer, default 50) – Number of trials of SMAC search i.e. runcount_limit of SMAC.
max_opt_time (union type, not for optimizer, default None) –
Maximum amount of time in seconds for the optimization.
float, >=0.0
or None
No runtime bound.
lale_num_grids (union type, not for optimizer, default None) –
None
If not set, keep all grids.
or float, >0.0, <1.0
Fraction of grids to keep.
or integer, >=1
Number of grids to keep.
- fit(X, y=None, **fit_params)¶
Train the operator.
Note: The fit method is not available until this operator is trainable.
Once this method is available, it will have the following signature:
- Parameters
X (array) –
items : union type
array of items : number or string
or string
y (array of items : float) –
- predict(X, **predict_params)¶
Make predictions.
Note: The predict method is not available until this operator is trained.
Once this method is available, it will have the following signature:
- Parameters
X (array, optional) –
items : union type
array of items : number or string
or string
- Returns
result
- Return type
array of items : float