Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Model Selection

Model selection tools automate hyperparameter search using cross-validation. SeraPlot provides four search strategies, from exhaustive grid search to efficient successive halving.

ClassStrategyDescription
GridSearchCVExhaustiveEvaluates every combination in the parameter grid
RandomizedSearchCVRandomSamples n_iter combinations uniformly at random
HalvingGridSearchCVHalvingExhaustive candidates + successive halving to reduce cost
HalvingRandomSearchCVHalving + RandomRandom candidates + successive halving

All four are documented on the same page: GridSearchCV / RandomizedSearchCV / Halving.

Choosing a search strategy

SituationRecommended
Small parameter gridGridSearchCV
Large parameter spaceRandomizedSearchCV
Large dataset + large gridHalvingGridSearchCV
Large dataset + large spaceHalvingRandomSearchCV

Quick example

import seraplot as sp
import numpy as np

X = np.random.randn(500, 5)
y = (X[:, 0] + X[:, 1] > 0).astype(int)

gs = sp.GridSearchCV(
    "LogisticRegression",
    {"C": [0.01, 0.1, 1.0, 10.0]},
    cv=5,
    scoring="accuracy",
)
gs.fit(X, y)
print(f"Best C: {gs.best_params_}")
print(f"CV accuracy: {gs.best_score_:.4f}")

Les outils de sélection de modèles automatisent la recherche d'hyperparamètres par validation croisée. SeraPlot propose quatre stratégies de recherche, de la grille exhaustive au halving successif efficace.

ClasseStratégieDescription
GridSearchCVExhaustiveÉvalue toutes les combinaisons de la grille de paramètres
RandomizedSearchCVAléatoireÉchantillonne n_iter combinaisons uniformément au hasard
HalvingGridSearchCVHalvingCandidats exhaustifs + halving successif pour réduire le coût
HalvingRandomSearchCVHalving + AléatoireCandidats aléatoires + halving successif

Les quatre sont documentés sur la même page : GridSearchCV / RandomizedSearchCV / Halving.

Choisir une stratégie de recherche

SituationRecommandé
Petite grille de paramètresGridSearchCV
Grand espace de paramètresRandomizedSearchCV
Grand jeu de données + grande grilleHalvingGridSearchCV
Grand jeu de données + grand espaceHalvingRandomSearchCV

Exemple rapide

import seraplot as sp
import numpy as np

X = np.random.randn(500, 5)
y = (X[:, 0] + X[:, 1] > 0).astype(int)

gs = sp.GridSearchCV(
    "LogisticRegression",
    {"C": [0.01, 0.1, 1.0, 10.0]},
    cv=5,
    scoring="accuracy",
)
gs.fit(X, y)
print(f"Meilleur C : {gs.best_params_}")
print(f"Précision CV : {gs.best_score_:.4f}")