pythonintermediate

AutoML with FLAML for Fast Tuning

Run automated machine learning with FLAML to find the best model and hyperparameters efficiently.

python
from flaml import AutoML
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
import numpy as np

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

automl = AutoML()
automl.fit(
    X_train, y_train,
    task='classification',
    time_budget=30,
    metric='roc_auc',
    n_jobs=-1,
    verbose=1,
)

print('Best estimator:', automl.best_estimator)
print('Best config:',    automl.best_config)
print('Best AUC:',       automl.best_loss)

preds = automl.predict(X_test)
print(classification_report(y_test, preds))

Use Cases

  • automated ML
  • model selection
  • rapid prototyping

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.