pythonintermediate
AutoML with FLAML for Fast Tuning
Run automated machine learning with FLAML to find the best model and hyperparameters efficiently.
pythonPress ⌘/Ctrl + Shift + C to copy
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.
pythonintermediate
SHAP Model Explainability in Python
Explain ML model predictions globally and locally using SHAP values with tree-based models.
Best for: model interpretability
#shap#explainability
pythonintermediate
Optuna Hyperparameter Optimization
Automate hyperparameter search with Optuna using Bayesian optimization and pruning.
Best for: AutoML
#optuna#hyperparameter
pythonintermediate
Custom sklearn Pipeline with Transformer
Build a custom scikit-learn Pipeline with a custom BaseEstimator Transformer for data preprocessing.
Best for: custom preprocessing
#sklearn#pipeline
pythonintermediate
LightGBM Feature Importance Analysis
Train a LightGBM model and analyse feature importance using split, gain, and permutation methods.
Best for: feature selection
#lightgbm#feature-importance