Search code examples
scikit-learncross-validation

What's the default score function in validation_curve in sklearn?


I'm running the following line of code:

validation_curve(PolynomialRegression(),X,y,
                 param_name='polynomialfeatures__degree',
                 param_range=degree,cv=7)

And, when I draw the validation_curve I get very negative scores for higher degrees. When I checked the documentation, it stated

scoring:str or callable, default=None A str (see model evaluation documentation) or a scorer callable object / function with signature scorer(estimator, X, y).

I'm just wondering what is the default score function in validation_curve in sklearn? If it's None, then how can they compute a score?


Solution

  • It defaults to the score method of the estimator, which in turn is often either accuracy (classification) or R2 (regression).

    In the source for validation_curve, it calls check_scorer, which in part contains:

        elif scoring is None:
            if hasattr(estimator, 'score'):
                return _passthrough_scorer
    

    where _passthrough_scorer just wraps the estimator's score:

    def _passthrough_scorer(estimator, *args, **kwargs):
        """Function that wraps estimator.score"""
        return estimator.score(*args, **kwargs)