Automatic model selection and tuning under a wall-clock budget.
AutoMLClassifier and AutoMLRegressor take a dataset and a number of seconds, and give back a fitted model, a leaderboard of everything they tried, and -- the part that makes the result portable -- best_spec_, the winning configuration written as a train spec. The spec is plain JSON-compatible data, so the outcome of a search can be committed to a repository, diffed, reviewed, and replayed without re-running the search.Classes
Automatic classifier selection and tuning under a time budget.
Overview
- Rank the library's classifiers cheap-and-strong first
build_portfolio).
- Evaluate every candidate at its defaults, then narrow the field by
search_space_for) until the wall-clock budget is spent.
- Optionally combine the fitted trials with greedy ensemble selection
greedy_selection).
-
Publish the winner as
best_spec_, atrainspec.
Parameters
time_budget
metric
metrics, or a callable (y_true, y_pred) -> float. Loss-style names are negated automatically. Defaults to "accuracy_score".
cv
None (or 1) switches to a single stratified 75/25 holdout, which is roughly cv times cheaper per trial.
random_state
ensemble
candidates
max_candidates
max_candidates.
n_ensemble_rounds
halving_factor
1 / halving_factor of the field and multiplies the draws per survivor by the same amount. 1 disables elimination and gives every candidate an equal share of the budget, which is what plain round-robin random search does.
acquisition
AcquisitionFunction.
verbose
Attributes
best_spec_
train spec: {"model": {"name": ..., "params": {...}}, "pipeline": [], "evaluation": {...}}. JSON-serialisable, so a search result can be committed and replayed.
best_estimator_
best_name_, best_params_, best_score_
leaderboard_
{"rank", "name", "score", "params"}, best first.
failed_
ensemble_
ensemble=True and it beat the best single model.
portfolio_
eliminated_
leaderboard_ shows where the budget stopped going.
survivors_
rungs_
search_time_
Notes
Complexity. One fit per trial (cv + 1 fits when cv >= 2); the trial count is whatever the budget allows. Ensemble selection is O(R \cdot M \cdot n) for R rounds, M pool members and n validation rows, with no model fitting at all.
When to use. As a strong first pass on a new tabular dataset, or to generate a starting train() spec to hand-tune afterwards. When the algorithm is already known, tune it directly with RandomSearchCV and skip the portfolio.
References
See Also
>>> from tuiml.automl import AutoMLClassifier
>>> from tuiml.datasets import load_iris
>>> data = load_iris()
>>> automl = AutoMLClassifier(time_budget=5, cv=3, random_state=0).fit(
... data.X, data.y)
>>> automl.best_spec_["model"]["name"] # doctest: +SKIP
'LogisticRegression'
>>> automl.leaderboard_[0]["score"] > 0.9
True
The spec is the deliverable -- replay it with train:
>>> import tuiml
>>> spec = dict(automl.best_spec_, data={"X": data.X, "y": data.y})
>>> model = tuiml.train(spec) # doctest: +SKIP
Methods
Automatic regressor selection and tuning under a time budget.
AutoMLClassifier: same three-stage search (portfolio, schema-derived sampling, greedy ensembling) and the same best_spec_ deliverable, scoring with R^2 by default and averaging predicted values rather than class probabilities.Parameters
time_budget
metric
metrics or a callable. Error metrics such as "mean_squared_error" are negated automatically so that higher always means better. Defaults to "r2_score".
cv
None uses a 75/25 holdout.
random_state
ensemble
candidates
max_candidates
n_ensemble_rounds
verbose
Attributes
best_spec_
train spec.
best_estimator_
best_name_, best_params_, best_score_
leaderboard_
failed_
ensemble_
portfolio_
search_time_
Notes
Complexity. cv + 1 fits per trial; the trial count is set by the budget. Ensemble selection fits nothing.
When to use. As a first pass on a new tabular regression problem. For a known algorithm, tune it directly with RandomSearchCV.
References
See Also
>>> from tuiml.automl import AutoMLRegressor
>>> from tuiml.datasets import load_cpu
>>> data = load_cpu()
>>> automl = AutoMLRegressor(time_budget=5, cv=3, random_state=0).fit(
... data.X, data.y)
>>> automl.best_score_ > 0.5
True
>>> sorted(automl.best_spec_)
['evaluation', 'model', 'pipeline']