AutoML with a time budget in FLAML
Goal: Letting the library choose the model and its hyperparameters within a set number of seconds.
from flaml import AutoML
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
X, y = load_breast_cancer(return_X_y=True)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.25, random_state=0)
automl = AutoML()
automl.fit(X_tr, y_tr, task="classification", time_budget=15, metric="roc_auc", verbose=0, seed=0)
print("Selected model:", automl.best_estimator)
print(f"Test accuracy: {(automl.predict(X_te) == y_te).mean():.3f}")
Code explanation
We set a time budget in seconds, and FLAML tries models such as LightGBM, XGBoost and random forests in a cost-aware order. The result varies slightly between machines because the search is time-bound.
Output recorded during testing
Selected model: lgbm Test accuracy: 0.979
This example was actually run and tested on 21 November 2026 on a CPU — flaml 2.8.0, scikit-learn 1.9.1, python 3.13.18
