Back to questionsHow many times is
JuniorTheoryCommon
How many times is LogisticRegression trained when this program runs?
from sklearn.datasets import load_wine
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
X, y = load_wine(return_X_y=True)
pipe = Pipeline([("scaler", StandardScaler()), ("model", LogisticRegression())])
grid = {"model__C": [0.1, 1.0, 10.0], "model__fit_intercept": [True, False]}
search = GridSearchCV(pipe, grid, cv=5)
search.fit(X, y)31
- Expecting
30: 6 candidates on 5 folds make 30 trainings, and then the best candidate is trained once more on all the data, which makes 31. - Expecting
26: the grid tries every combination, so 3 values ofCand 2 offit_interceptgive 6 candidates, not 5; 6 × 5 + 1 is 31.
- How many trainings would a random search (
RandomizedSearchCV) withn_iter=4andcv=5make here? - Why does the number of hyperparameters limit how far a grid search can go?