Skip to content

No score output when using BaseSearchCV with appropriate verbosity and non-dict scoring #19658

Closed
@hsorsky

Description

@hsorsky

Describe the bug

I am not sure if this counts as a bug or a regression (or whether it was discussed and purposefully done, but I can't see any documentation of it).

Previously (sklearn version 0.20.1) when running fit on a BaseSearchCV object with verbosity above 2, we would get output detailing the test scores for each fold. Under current sklearn (0.24.1), if we don't supply scorers through a dictionary, there is no output regarding fold scores. It can be seen that this is the case here

I assume intended logic was

if verbose > 2:
    if isinstance(test_scores, dict):
        # handle multiple scores
    else:
        # handle single score
...

Steps/Code to Reproduce

Run RandomizedSearchCV or GridSearchCV fit with verbose > 2 and some provided arg for scoring.

Example:

import numpy as np
from sklearn.model_selection import GridSearchCV

X = np.array([
    [0.1, 0.2, 0.3],
    [0.1, 0.2, 0.3],
])
y = np.array([1, 2])

from sklearn.linear_model import LinearRegression

cross_validator = GridSearchCV(
    estimator=LinearRegression(),
    param_grid={"fit_intercept": [True, False]},
    scoring="neg_mean_squared_error",
    verbose=3,
    cv=2,
    refit=False,
)

cross_validator.fit(X, y)

Expected Results

Fitting 2 folds for each of 2 candidates, totalling 4 fits
[CV 1/2] END .............................fit_intercept=True; score=-1.0; total time=   0.0s
[CV 2/2] END .............................fit_intercept=True; score=-1.0; total time=   0.0s
[CV 1/2] END ............................fit_intercept=False; score=-1.0; total time=   0.0s
[CV 2/2] END ............................fit_intercept=False; score=-1.0; total time=   0.0s

Actual Results

Fitting 2 folds for each of 2 candidates, totalling 4 fits
[CV 1/2] END .............................fit_intercept=True; total time=   0.0s
[CV 2/2] END .............................fit_intercept=True; total time=   0.0s
[CV 1/2] END ............................fit_intercept=False; total time=   0.0s
[CV 2/2] END ............................fit_intercept=False; total time=   0.0s

Versions

Darwin-19.6.0-x86_64-i386-64bit
Python 3.7.4 (default, May  4 2020, 18:19:10) 
[Clang 11.0.3 (clang-1103.0.32.59)]
NumPy 1.20.1
SciPy 1.6.1
Scikit-Learn 0.24.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions