LazyTune Docs
A fast and efficient hyperparameter optimization framework for scikit-learn models. Dramatically reduces training time with a smart screening → pruning → full-training pipeline.
Overview
LazyTune wraps any scikit-learn estimator and searches a parameter grid the way an experienced practitioner would: cheap screening first, then spend full training budget only on configurations that already look promising.
Installation
Install LazyTune via pip. No extra configuration needed — all dependencies are pulled in automatically.
1$ pip install lazytuneRequires Python 3.8+, numpy, pandas, and scikit-learn.
Quick Start
Get up and running with RandomForestClassifier on the breast cancer dataset in under a minute.
1from sklearn.datasets import load_breast_cancer2from sklearn.ensemble import RandomForestClassifier3from lazytune import SmartSearch 5X, y = load_breast_cancer(return_X_y=True)6param_grid = {7 "n_estimators": [50, 100, 150, 200],8 "max_depth": [5, 10, 15, None],9 "min_samples_split": [2, 3, 4, 5]10} 12search = SmartSearch(13 estimator=RandomForestClassifier(random_state=42),14 param_grid=param_grid,15 metric="accuracy",16 cv_folds=3,17 prune_ratio=0.5, # keep top 50% after screening18 n_jobs=-1 # use all available cores19) 21search.fit(X, y)22print("Best parameters:", search.best_params_)23print("Best CV score:", search.best_score_)24print("\nBest model:\n", search.best_estimator_)SVM Classification
Use SmartSearch with a Support Vector Machine to tune C, kernel, and gamma together.
1from sklearn.svm import SVC2from lazytune import SmartSearch 4search = SmartSearch(5 estimator=SVC(random_state=42),6 param_grid={7 "C": [0.1, 1, 10, 50, 100],8 "kernel": ["linear", "rbf"],9 "gamma": ["scale", "auto", 0.001, 0.0001]10 },11 metric="f1_macro",12 cv_folds=5,13 prune_ratio=0.614)Regression
Works identically for regression — just switch the estimator and use a regression metric like r2.
1from sklearn.ensemble import RandomForestRegressor2from lazytune import SmartSearch 4search = SmartSearch(5 estimator=RandomForestRegressor(random_state=42),6 param_grid={7 "n_estimators": [100, 200, 300, 500],8 "max_depth": [8, 12, 16, None],9 "min_samples_split": [2, 4, 8]10 },11 metric="r2",12 cv_folds=4,13 n_jobs=-114)Supported Metrics
LazyTune supports all scikit-learn scoring strings. Pass any as the metric argument. For custom metrics use sklearn.metrics.make_scorer.
How It Works
LazyTune’s four-phase pipeline eliminates wasted compute compared to brute-force GridSearchCV — while typically reaching identical final performance.
API Reference
All functionality is exposed through the SmartSearch class.
1SmartSearch(2 estimator, # any scikit-learn style estimator3 param_grid, # dict of param -> list of values4 metric, # scoring string or make_scorer object5 cv_folds=3, # number of CV folds for screening6 prune_ratio=0.5, # fraction to prune (0.0 = keep all)7 n_jobs=1 # parallel workers (-1 = all cores)8)Attributes
| Attribute | Type | Description |
|---|---|---|
best_params_ | dict | Best found hyperparameter dictionary. |
best_score_ | float | Best cross-validated score achieved. |
best_estimator_ | estimator | Fully fitted estimator with best parameters. |
summary_ | DataFrame | pandas DataFrame with all trial results and rankings. |
cv_results_ | dict | Detailed cross-validation results per candidate. |
Methods
| Method | Description |
|---|---|
.fit(X, y) | Run the full optimization pipeline on training data. |
.predict(X) | Predict using the best found estimator. |
.score(X, y) | Score the best estimator on given data. |
.get_params() | Get parameters for this estimator. |
.set_params(**params) | Set parameters of this estimator. |
Requirements
- Python ≥ 3.8
- numpy
- pandas
- scikit-learn
All dependencies are installed automatically via pip.
License & Author
LazyTune is released under the MIT License — free to use, modify, and distribute. Built by Anik Chand. Feedback, issues, stars, and contributions are very welcome!
GitHub