Skip to content

DOC error message when checking response values of an estimator not clear #33093

Closed

Description

@qbarthelemy

Describe the issue linked to the documentation

Current function that checks response values of an estimator
assumes that if the estimator is not a classifier or an outlier detector, then it is a regressor.

In the latter case, if it doesn't find the predict function,
it raises an error stating that the estimator is a regressor: ValueError: ... Got a regressor....

However, the estimator might be something other than a regressor.

For example, it can be a classification Pipeline with a MRO issue, see NeuroTechX/moabb#815
Many other GitHub repositories have reported this ambiguous error, see list in #33084 (comment)

The goal of this issue is to discuss how to correct the message by making it clearer,
specifically by no longer stating that it is a regressor.

Suggest a potential alternative/fix

Current function _get_response_values.py in scikit-learn/sklearn/utils/_response.py

    else:  # estimator is a regressor
        if response_method != "predict":
            raise ValueError(
                f"{estimator.__class__.__name__} should either be a classifier to be "
                f"used with response_method={response_method} or the response_method "
                "should be 'predict'. Got a regressor with response_method="
                f"{response_method} instead."
            )
        prediction_method = estimator.predict
        y_pred, pos_label = prediction_method(X), None

could be corrected into

    elif is_regressor(estimator):
        prediction_method = estimator.predict
        y_pred, pos_label = prediction_method(X), None
    else:
        raise ValueError(
            f"{estimator.__class__.__name__} is not recognized as a classifier, "
            "an outlier detector or a regressor."
        )

and, if necessary, we could add before else

    elif is_clusterer(estimator):
        prediction_method = ...
        y_pred, pos_label = ...

Activity

  1. SSVP-debug commented on Jan 16, 2026

    @SSVP-debug

    Hello @qbarthelemy , I’m a first-time contributor. May I work on this issue?

  2. AnneBeyer commented on Jan 16, 2026

    @AnneBeyer
    Member

    Hi @SSVP-debug, thank you for your interest, but please check Issues tagged “Needs Triage”. Note also that @qbarthelemy might be interested in working on this himself once consensus has been reached on how to handle this issue.

  3. AnneBeyer commented on Jan 16, 2026

    @AnneBeyer
    Member

    Thank you for raising this again as an issue @qbarthelemy.

    From what I understand, there is no reason why

    • clusterers should not be supported and
    • outlier detectors and regressors would need to be handled differently.

    My suggestion would be to move

    prediction_method = _check_response_method(estimator, response_method)

    to the top of the function, because this will check if the requested method is available for all types of estimators and raise a comprehensive AttributeError if it is not implemented.
    (This should be backed up by corresponding tests, though.)

    Then the elif for outlier detectors can be removed and the else can be reduced to

    y_pred, pos_label = prediction_method(X), None

    to cover all other cases (outlier detectors, regressors and clusterers).

    Could any of you please double-check if I missed anything, @glemaitre @jeremiedbb @thomasjpfan @ogrisel?


    Note to myself:
    This would also already be a step towards #33015 (comment), and might also reduce the need for treating regressors separately when resolving "auto" here, as the list would be reduced to predict
    by _get_response_values

    if response_method == "auto":
    if is_regressor(estimator):
    prediction_method = "predict"
    else:
    prediction_method = ["decision_function", "predict_proba", "predict"]

  4. thomasjpfan commented on Jan 18, 2026

    @thomasjpfan
    Member

    @AnneBeyer At a glance your analysis looks correct to me and should simplify _get_response_values.

  5. moved this from Todo to In progress in Labson Jan 19, 2026
  6. removed
    Needs Triage
    on Jan 23, 2026
  7. ogrisel commented on Jan 23, 2026

    @ogrisel
    Member

    I would indeed be in favor of first trying what @AnneBeyer suggests to check if it works as anticipated. @qbarthelemy @AnneBeyer any of you interested in opening a PR?

  8. qbarthelemy commented on Jan 23, 2026

    @qbarthelemy
    ContributorAuthor

    I opened a PR here #33126

  9. AdoDeBrilliance commented on Feb 2, 2026

    @AdoDeBrilliance

    Hi team 👋
    I'm a student contributor and would like to improve the documentation for this issue.
    May I work on this?
    Thanks!

  10. moved this from In progress to Done in Labson Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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