Skip to content

H2ML

Python PyPI

A 4-step AutoML pipeline for tabular data that wraps sklearn-compatible estimators. Given a feature matrix and target, it screens all registered models, reduces features via SHAP importance and correlation filtering, and tunes the winner with Optuna — all in one call.

from h2ml import H2MLPipeline, PipelineConfig, PipelineData

store = PipelineData.from_frame(X, y=y_arr)

pipeline = H2MLPipeline(config=PipelineConfig(task_type="classification", metric="AUC"))
result = pipeline.run(store)

print(result.summary())
final = result.build_final_model()   # refit on the full training set

How it works

Step What happens
1 K-fold CV all models (× optional y-transforms) on all features
2 SHAP importance → correlation-based feature drop (optional VIF filter)
3 K-fold CV all models on reduced features (winning transform only); compare vs step 1
4 Optuna HPO on the winning (model, stage, transform); skipped if the winner has no enabled search space

The pipeline can also be run partially: run_step1_only() screens models, and run_from_step3() / run_step4_only() resume from a previous result. With holdout_frac > 0, rows are set aside before step 1 and the final configuration is scored once on them.

Features

Core pipeline

  • Model screening — a curated set of sklearn classifiers and regressors in one parallel CV pass
  • Optional boosting — LightGBM, XGBoost, CatBoost registered when installed
  • Custom models — your own estimators, a subset of the registry, or different search spaces
  • SHAP feature selection — out-of-fold SHAP avoids leaking importance scores
  • Cross-validation — stratified k-fold for classification and k-fold for regression, or spatial block and AHC-based splitters when store.coords is set
  • y-transform sweep — log, sqrt, and winsorized variants evaluated jointly
  • Persistence — Parquet + npy + joblib; reload a run and resume from step 3 or 4

Trustworthy selection

Before and after the pipeline