Initializing LazyTune
LazyTune
Hyperparameter Optimizer
Ready
v1.0 — Stable

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.

ClassificationRegressionscikit-learn compatiblePython ≥ 3.8MIT License

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.

bash
1$ pip install lazytune

Requires 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.

python
1from sklearn.datasets import load_breast_cancer
2from sklearn.ensemble import RandomForestClassifier
3from 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 screening
18 n_jobs=-1 # use all available cores
19)
 
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.

python
1from sklearn.svm import SVC
2from 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.6
14)

Regression

Works identically for regression — just switch the estimator and use a regression metric like r2.

python
1from sklearn.ensemble import RandomForestRegressor
2from 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=-1
14)

Supported Metrics

LazyTune supports all scikit-learn scoring strings. Pass any as the metric argument. For custom metrics use sklearn.metrics.make_scorer.

Classification
accuracyf1f1_macrof1_weightedprecisionrecallroc_aucbalanced_accuracy
Regression
r2neg_mean_squared_errorneg_root_mean_squared_errorneg_mean_absolute_errorneg_mean_absolute_percentage_error

How It Works

LazyTune’s four-phase pipeline eliminates wasted compute compared to brute-force GridSearchCV — while typically reaching identical final performance.

1
Generate Combinations
All hyperparameter combinations are produced from the user-defined param_grid.
2
Screening Round
Every candidate is quickly evaluated with cross-validation using minimal resources — just enough to rank relative performance.
3
Rank & Prune
Candidates are sorted by screening score. The bottom prune_ratio fraction are eliminated before full training begins.
4
Full Training
Only top-ranked survivors are trained fully. The best model, parameters, score and detailed trial summary are returned.

API Reference

All functionality is exposed through the SmartSearch class.

signature
1SmartSearch(
2 estimator, # any scikit-learn style estimator
3 param_grid, # dict of param -> list of values
4 metric, # scoring string or make_scorer object
5 cv_folds=3, # number of CV folds for screening
6 prune_ratio=0.5, # fraction to prune (0.0 = keep all)
7 n_jobs=1 # parallel workers (-1 = all cores)
8)

Attributes

AttributeTypeDescription
best_params_dictBest found hyperparameter dictionary.
best_score_floatBest cross-validated score achieved.
best_estimator_estimatorFully fitted estimator with best parameters.
summary_DataFramepandas DataFrame with all trial results and rankings.
cv_results_dictDetailed cross-validation results per candidate.

Methods

MethodDescription
.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