Skip to main content

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 to refit=... that picks the parameter set balancing high test performance and small train–test gap.

Best Use cases

-Accuracy, Balanced Accuracy

-Precision, Recall, F1, Jaccard similarity

-ROC AUC, PR AUC

-Matthews correlation coefficient (MCC, normalized variant)


Why?

Vanilla GridSearchCV usually selects the highest mean test score, which can sometimes favor models with high variance.
selector_mean instead minimizes: 0.5 * (|train - test|) + 0.5 * (1 - test)
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 fitsearhcv

Github link: Github


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,
                   cv=5, 
                   return_train_score=True,
                   n_jobs=-1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fitsearchcv-1.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fitsearchcv-1.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file fitsearchcv-1.0.1.tar.gz.

File metadata

  • Download URL: fitsearchcv-1.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for fitsearchcv-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b9c811de4c8ea4cc61af4a930af2385bc2ef038203a67397ce12c9597b4672a3
MD5 ace4a34c3d0b6330623eabb8ab3dbe84
BLAKE2b-256 72ae2737662f126e788b64433b7a7d02d7709d1106fcb663f295bfe898829a8a

See more details on using hashes here.

File details

Details for the file fitsearchcv-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fitsearchcv-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for fitsearchcv-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d82fb3349e6e30eed7d926925d7d7053db747ab3466d995c062d18df2e5be04
MD5 5697302d5501330c643385d9d4e4bf5c
BLAKE2b-256 d45574940feaf9a33d6a39d7fae187718e9c4113b880bd9c94d4fd26f902c0c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page