Hyperparameter tuning is one of the most expensive steps in machine learning.
The standard solution is usually:
GridSearchCV(...)But Grid Search has a major drawback:
❌ Trains every parameter combination
❌ Wastes time on obviously poor configurations
❌ Scales poorly as search spaces grow
❌ Can take hours for large models
❌ Most configurations never had a chance of winning
For example:
n_estimators = [50,100,150,200]
max_depth = [5,10,15,None]
min_split = [2,3,4,5]
4 × 4 × 4 = 64 full trainings
Yet only a handful of those candidates are actually promising.
LazyTune fixes this.
- 100% compatible with any scikit-learn-style estimator
- Works for classification & regression
- Supports all scikit-learn metrics + custom scorers
- Smart pipeline: screening → ranking → pruning → full training
- Early pruning of poor configurations (
prune_ratio) - Parallel execution (
n_jobs) - Clean trial summaries & rankings in pandas DataFrame
- Returns best model, params, score + detailed report
pip install lazytunefrom sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from lazytune import SmartSearch
X, y = load_breast_cancer(return_X_y=True)
param_grid = {
"n_estimators": [50, 100, 150, 200],
"max_depth": [5, 10, 15, None],
"min_samples_split": [2, 3, 4, 5]
}
search = SmartSearch(
estimator=RandomForestClassifier(random_state=42),
param_grid=param_grid,
metric="accuracy",
cv_folds=3,
prune_ratio=0.5, # keep top 50% after screening
n_jobs=-1 # use all cores
)
search.fit(X, y)
print("Best parameters:", search.best_params_)
print("Best CV score: ", search.best_score_)
print("\nBest model:\n", search.best_estimator_)from sklearn.svm import SVC
from lazytune import SmartSearch
search = SmartSearch(
estimator=SVC(random_state=42),
param_grid={
"C": [0.1, 1, 10, 50, 100],
"kernel": ["linear", "rbf"],
"gamma": ["scale", "auto", 0.001, 0.0001]
},
metric="f1_macro",
cv_folds=5,
prune_ratio=0.6
)from sklearn.ensemble import RandomForestRegressor
from lazytune import SmartSearch
search = SmartSearch(
estimator=RandomForestRegressor(random_state=42),
param_grid={
"n_estimators": [100, 200, 300, 500],
"max_depth": [8, 12, 16, None],
"min_samples_split": [2, 4, 8]
},
metric="r2",
cv_folds=4,
n_jobs=-1
)accuracy • f1 • f1_macro • f1_weighted • precision • recall • roc_auc • balanced_accuracy • ...
r2 • neg_mean_squared_error • neg_root_mean_squared_error • neg_mean_absolute_error • ...
Custom metrics → use sklearn.metrics.make_scorer
- Generate all (or sampled) hyperparameter combinations
- Quick screening round with cross-validation
- Rank configurations by performance
- Prune bottom performers (
prune_ratio) - Train remaining promising candidates thoroughly
- Return best model + full trial summary
→ Much faster than GridSearchCV / RandomizedSearchCV
→ Usually very close (or identical) final performance
| Attribute | Description |
|---|---|
best_params_ |
Best hyperparameter dictionary |
best_score_ |
Best cross-validated score |
best_estimator_ |
Fully fitted estimator with best parameters |
summary_ |
pandas DataFrame with trial results & rankings |
cv_results_ |
Detailed CV results per candidate |
.fit(X, y).predict(X).score(X, y).get_params()/.set_params()
- Python ≥ 3.8
- numpy
- pandas
- scikit-learn
Made with ❤️ by Anik Chand
MIT License
Feedback, issues, stars, and contributions are very welcome! 🌟
Try Live Demo • Install from PyPI
Happy tuning! 🚀


