A smarter refit to sklearn.GridSearchCV and sklearn.RandomizedSearchCV to reduce over and underfitting
Project description
FitSearchCV— A smarter refit selector for scikit-learn searches
selector-mean is a tiny utility that helps reduce overfitting and underfitting when tuning hyperparameters with scikit-learn’s GridSearchCV or RandomizedSearchCV.
It provides a single function:
selector_mean(cv_results_, metric=None, use_abs_gap=True, clip01=True)
A callable you pass torefit=...that picks the parameter set balancing high test performance and small train–test gap.
Best Use cases
-
accuracy_score
-
balanced_accuracy_score
-
precision_score (binary, micro, macro, weighted)
-
recall_score (binary, micro, macro, weighted)
-
f1_score (binary, micro, macro, weighted)
-
roc_auc_score
-
average_precision_score
-
jaccard_score
Why?
Vanilla GridSearchCV usually selects the highest mean test score, which can sometimes favor models with high variance.
Here, test refers to as validation accuracy.
selector_mean instead minimizes: ((|train - test|) + (1 - test))/2
This prevents both underfittnig and overfitting.
|train-test| is for reducing the gap between train and test accuracy thus decreasing overfitting.
(1-test) is for reducing the gap between test accuracy and 1 hence increasing the score thus reducing underfitting.
Want to try?
Just type
pip install fitsearchcv
PyPI link: PyPI
How to Use?
from fitsearchcv.selectors import selector_mean
from sklearn.model_selection import GridSearchCV
from sklearn.linear_model import LogisticRegression
lr=LogisticRegression()
param_grid = [
{'penalty': ['l1'], 'C': [0.1, 1, 10], 'solver': ['liblinear', 'saga']},
{'penalty': ['l2'], 'C': [0.1, 1, 10], 'solver': ['liblinear', 'lbfgs', 'saga', 'sag', 'newton-cg']},
{'penalty': ['elasticnet'], 'C': [0.1, 1, 10], 'solver': ['saga'], 'l1_ratio': [0.0, 0.25, 0.5, 0.75, 1.0]},
{'penalty': [None], 'solver': ['lbfgs', 'sag', 'newton-cg', 'saga']}
]
grid1=GridSearchCV(estimator=lr,
param_grid=param_grid,
refit=selector_mean, # added line
cv=5,
return_train_score=True,
n_jobs=-1)
Citation
If you use FitSearchCV in academic or research work, a citation or acknowledgement
would be appreciated. See CITATION.cff for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fitsearchcv-1.0.3.tar.gz.
File metadata
- Download URL: fitsearchcv-1.0.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92b86f6b70f2a2c4f12c3d9813fe39bec22c9618c9425f90920b9f003c4b1b41
|
|
| MD5 |
691e1367a64f0425879d67a358bbf96d
|
|
| BLAKE2b-256 |
0f27fe41f30c2aab14afe35a229b86d88c4b2f469a01b8adc703b5f05e62f517
|
File details
Details for the file fitsearchcv-1.0.3-py3-none-any.whl.
File metadata
- Download URL: fitsearchcv-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3536b417e09cf4c12ba5703cafd164da5ea02c3123c27d1a5d477c084cd6f564
|
|
| MD5 |
203412c8cdee536c733a30eb183be361
|
|
| BLAKE2b-256 |
fb09cc8b5475193d7c94f1620773bee1d5e83484440cb42ab1f33e4fa6037951
|