Thursday, September 10, 2026
HomeData ScienceAutomated Machine Learning – AutoML with Python (AutoSklearn, FLAML, H2O) 2026

Automated Machine Learning – AutoML with Python (AutoSklearn, FLAML, H2O) 2026

Table of Content

AutoML automates the most time-consuming parts of machine learning — algorithm selection, feature preprocessing, and hyperparameter tuning. It does not replace data scientists, but it dramatically accelerates baseline model creation and often discovers pipeline configurations that a human would not have tried. This guide covers the leading AutoML frameworks in Python with real code and honest limitations.

When to Use AutoML

AutoML is most valuable for quickly establishing a strong baseline, evaluating whether ML is worth investing in for a new problem, freeing up time for higher-value work like feature engineering and business problem formulation, and making ML accessible to domain experts without deep ML knowledge. It is less valuable when you have strong domain intuition about the right model type, when interpretability constraints rule out most algorithms, or when compute budget is very tight.

FLAML – Fast and Lightweight AutoML

pip install flaml[automl]

from flaml import AutoML
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
import pandas as pd
import time

X, y   = make_classification(n_samples=5000, n_features=25,
                               n_informative=15, random_state=42)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=42)

automl = AutoML()

start = time.time()
automl.fit(
    X_train=X_tr, y_train=y_tr,
    task='classification',
    metric='roc_auc',
    time_budget=120,    # seconds — increase for better results
    estimator_list=['lgbm', 'xgboost', 'rf', 'extra_tree', 'lrl1'],
    n_jobs=-1,
    verbose=1
)
elapsed = time.time() - start

print(f'Time: {elapsed:.0f}s')
print(f'Best model: {automl.best_estimator}')
print(f'Best config: {automl.best_config}')
print(f'Best CV AUC: {1 - automl.best_loss:.4f}')

y_pred = automl.predict_proba(X_te)[:, 1]
print(f'Test AUC: {roc_auc_score(y_te, y_pred):.4f}')

H2O AutoML

pip install h2o

import h2o
from h2o.automl import H2OAutoML

h2o.init(nthreads=-1, max_mem_size='4g')

# H2O requires H2OFrames
train_h2o = h2o.H2OFrame(pd.concat([
    pd.DataFrame(X_tr, columns=[f'f{i}' for i in range(X_tr.shape[1])]),
    pd.Series(y_tr, name='target')
], axis=1))
test_h2o = h2o.H2OFrame(pd.concat([
    pd.DataFrame(X_te, columns=[f'f{i}' for i in range(X_te.shape[1])]),
    pd.Series(y_te, name='target')
], axis=1))

train_h2o['target'] = train_h2o['target'].asfactor()
test_h2o['target']  = test_h2o['target'].asfactor()

features = [f'f{i}' for i in range(X_tr.shape[1])]

aml = H2OAutoML(
    max_runtime_secs=120,
    max_models=20,
    seed=42,
    sort_metric='AUC',
    exclude_algos=['DeepLearning']   # exclude slow algos
)
aml.train(x=features, y='target', training_frame=train_h2o)

# Leaderboard
print(aml.leaderboard.head(10))

# Best model
best = aml.leader
perf = best.model_performance(test_h2o)
print(f'Test AUC: {perf.auc():.4f}')

# Variable importance
print(best.varimp(use_pandas=True).head(10))

h2o.shutdown(prompt=False)

Auto-sklearn

pip install auto-sklearn   # Linux/Mac only — use Docker on Windows

import autosklearn.classification
from sklearn.metrics import accuracy_score

cls = autosklearn.classification.AutoSklearnClassifier(
    time_left_for_this_task=120,
    per_run_time_limit=30,
    n_jobs=-1,
    metric=autosklearn.metrics.roc_auc,
    ensemble_kwargs={'ensemble_size': 10}
)
cls.fit(X_tr, y_tr)

print(cls.leaderboard())
print(f'Test Accuracy: {accuracy_score(y_te, cls.predict(X_te)):.4f}')

Optuna for Custom AutoML

import optuna
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, PolynomialFeatures
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
import xgboost as xgb
import lightgbm as lgb

optuna.logging.set_verbosity(optuna.logging.WARNING)

def objective(trial):
    model_name = trial.suggest_categorical('model',
        ['rf', 'gb', 'xgb', 'lgb', 'lr'])

    if model_name == 'rf':
        model = RandomForestClassifier(
            n_estimators = trial.suggest_int('n_estimators', 50, 500),
            max_depth    = trial.suggest_int('max_depth', 3, 20),
            min_samples_split = trial.suggest_int('min_samples_split', 2, 20),
            random_state = 42, n_jobs=-1
        )
    elif model_name == 'xgb':
        model = xgb.XGBClassifier(
            n_estimators    = trial.suggest_int('n_estimators', 100, 1000),
            learning_rate   = trial.suggest_float('lr', 0.01, 0.3, log=True),
            max_depth       = trial.suggest_int('max_depth', 3, 9),
            subsample       = trial.suggest_float('subsample', 0.5, 1.0),
            use_label_encoder=False, eval_metric='logloss',
            random_state=42, n_jobs=-1
        )
    elif model_name == 'lgb':
        model = lgb.LGBMClassifier(
            n_estimators    = trial.suggest_int('n_estimators', 100, 1000),
            learning_rate   = trial.suggest_float('lr', 0.01, 0.3, log=True),
            num_leaves      = trial.suggest_int('num_leaves', 20, 200),
            random_state=42, n_jobs=-1, verbose=-1
        )
    else:
        model = LogisticRegression(
            C=trial.suggest_float('C', 0.01, 100, log=True),
            max_iter=500, random_state=42, n_jobs=-1
        )

    # Preprocessing
    scaler = trial.suggest_categorical('scaler', ['none', 'standard'])
    steps  = []
    if scaler == 'standard': steps.append(('scaler', StandardScaler()))
    steps.append(('model', model))
    pipe = Pipeline(steps)

    from sklearn.model_selection import cross_val_score
    scores = cross_val_score(pipe, X_tr, y_tr, cv=5,
                             scoring='roc_auc', n_jobs=-1)
    return scores.mean()

study = optuna.create_study(direction='maximize',
                             sampler=optuna.samplers.TPESampler(seed=42))
study.optimize(objective, n_trials=50, show_progress_bar=True)

print(f'
Best AUC: {study.best_value:.4f}')
print(f'Best params: {study.best_params}')

# Visualise
optuna.visualization.plot_param_importances(study).show()
optuna.visualization.plot_optimization_history(study).show()

Conclusion

FLAML is the best starting point for most problems — fast, lightweight, and produces excellent results within minutes. H2O AutoML provides more model variety (stacked ensembles, deep learning) and an excellent web UI for exploration. Auto-sklearn is the research standard but Linux-only. For maximum control and reproducibility, build your own AutoML loop with Optuna — it is just 50 lines of code and gives you full visibility into every decision. Whatever framework you choose, run AutoML to set your baseline, then invest your expertise in feature engineering and domain-specific improvements that AutoML cannot discover.

Leave feedback about this

  • Rating

Durgesh Kekare
Durgesh Kekarehttps://www.dataexpertise.in
Durgesh Kekare is a data science educator and founder of DataExpertise.in. With expertise in Python, machine learning, and analytics, he helps 10,000+ learners break into data careers.

Latest Posts

List of Categories