You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support clusterers in DecisionBoundaryDisplay #33119
So far, response_method="auto" does not resolve correctly (list of options as for classifiers instead of predict).
The approach I implemented is: using PCA, followed by DBSCAN and Logistic Regression as a final step.
Properly showing the relevant datapoints, categorised/colored by their identified clusters, would be great without an extra call to scatter.
Describe your proposed solution
As per discussion linked below, proper support for clusterers should be added to DecisionBoundaryDisplay.
Describe alternatives you've considered, if relevant
Simply plotting a scatterplot on top does not necessarily yield the same class colors, because the clusters are not necessarily ordered in the same way as the y values.
For the first point, I think we could limit clusterer support to the predict response method. Some clustering algorithms might be able to compute continuous cluster membership scores, but I we don't have a unified API for this, hence I would keep this out of the scope of this issue.
Furthermore, it's possible that some clustering algorithm do not expose a predict method. Only fit_predict or the labels_ fitted attribute. I think response_method="auto" should use the labels_ attribute in this case.
If OK,I’ll take this on and start working on fixing response_method="auto" for clusterers using labels_ when predict isn’t available. Just checking - does that match your expectation? Either way, I can start.
Furthermore, it's possible that some clustering algorithm do not expose a predict method. Only fit_predict or the labels_ fitted attribute. I think response_method="auto" should use the labels_ attribute in this case.
This case is a bit more complicated. To plot the decision boundary, we calculate the responses for an evenly spaced meshgrid (based on the min and max of X) in from_estimator, so the given estimator has to implement at least predict. If I'm not missing anything, we can't support any estimators that don't have that.
If my assumption is correct, resolving response_method="auto" can be simplified to the default value ["decision_function", "predict_proba", "predict"] for all estimators, which will be resolved into predict if the others are not implemented once this PR gets merged. The case where predict is not implemented will then be handled by an AttributeError in sklearn.utils.validation._check_response_method, and all that is left here to do would be to make this clear in the docstrings and extend the tests to include clusterers (that implement predict).
Please correct me, if I missed anything, I'm not that familiar with clustering applications yet.
Side note: I just learned about the inductive clustering example. We could add something like that in cases where a clusterer doesn't implement predict, but maybe this is too much of a special interest application? Maybe we could instead link to this example in the docs for people to use it themselves if they need to.
So far, response_method="auto" does not resolve correctly (list of options as for classifiers instead of predict).
How do you want it to resolve for clusterers? Do you want it to use predict or (from what I can tell from @AnneBeyer's comment) do you want it to work for clusterers that do not have a predict method?
Note on 'auto', it does cycle through (in order) ["decision_function", "predict_proba", "predict"], so it does get to predict.
(AFAICT I don't think there is anything to be done here)
For the second point, I think issue #33094 covers it.
I think this issue may be able to be closed - if there are no objections I will close in a few days.
Note on 'auto', it does cycle through (in order) ["decision_function", "predict_proba", "predict"], so it does get to predict.
This wasn't the case when this issue was opened (back then it threw an error for clusterers for anything other than response_method="predict"). This was fixed in #33126, though.
So in principle, this is already supported now, but what is left to do is to
make clusterer support explicit in the display docstrings,
extend the tests to include a clusterer (that implements predict),
extend an example to demonstrate the use of DecisionBoundaryDisplay.from_estimator on clustering problems (and possibly link to the inductive clustering example).
While none of these are code changes, I think it could still be worth keeping this open until those are done.
Activity
ogrisel commentedon Jan 21, 2026
I think there are two independent issues:
response_method="auto"so that it works as expected for clusterers,show_data=Falseoption toDecisionBoundaryDisplay.from_estimator#33094. We just need to ensure that clustering algorithms are properly handled.For the first point, I think we could limit clusterer support to the
predictresponse method. Some clustering algorithms might be able to compute continuous cluster membership scores, but I we don't have a unified API for this, hence I would keep this out of the scope of this issue.Furthermore, it's possible that some clustering algorithm do not expose a
predictmethod. Onlyfit_predictor thelabels_fitted attribute. I thinkresponse_method="auto"should use thelabels_attribute in this case.ogrisel commentedon Jan 21, 2026
We might also need to extend an example to demonstrate the use of
DecisionBoundaryDisplay.from_estimatoron clustering problems.shiffiH commentedon Jan 22, 2026
If OK,I’ll take this on and start working on fixing response_method="auto" for clusterers using labels_ when predict isn’t available. Just checking - does that match your expectation? Either way, I can start.
AnneBeyer commentedon Jan 28, 2026
This case is a bit more complicated. To plot the decision boundary, we calculate the responses for an evenly spaced meshgrid (based on the min and max of X) in
from_estimator, so the given estimator has to implement at leastpredict. If I'm not missing anything, we can't support any estimators that don't have that.If my assumption is correct, resolving
response_method="auto"can be simplified to the default value["decision_function", "predict_proba", "predict"]for all estimators, which will be resolved intopredictif the others are not implemented once this PR gets merged. The case wherepredictis not implemented will then be handled by anAttributeErrorinsklearn.utils.validation._check_response_method, and all that is left here to do would be to make this clear in the docstrings and extend the tests to include clusterers (that implementpredict).Please correct me, if I missed anything, I'm not that familiar with clustering applications yet.
AnneBeyer commentedon Feb 4, 2026
Side note: I just learned about the inductive clustering example. We could add something like that in cases where a clusterer doesn't implement
predict, but maybe this is too much of a special interest application? Maybe we could instead link to this example in the docs for people to use it themselves if they need to.lucyleeow commentedon Nov 12, 2026
Just doing some housekeeping.
How do you want it to resolve for clusterers? Do you want it to use predict or (from what I can tell from @AnneBeyer's comment) do you want it to work for clusterers that do not have a predict method?
Note on 'auto', it does cycle through (in order) ["decision_function", "predict_proba", "predict"], so it does get to predict.
(AFAICT I don't think there is anything to be done here)
For the second point, I think issue #33094 covers it.
I think this issue may be able to be closed - if there are no objections I will close in a few days.
AnneBeyer commentedon Nov 23, 2026
Just some historical context:
This wasn't the case when this issue was opened (back then it threw an error for clusterers for anything other than
response_method="predict"). This was fixed in #33126, though.So in principle, this is already supported now, but what is left to do is to
show_data=Falseoption toDecisionBoundaryDisplay.from_estimator#33094predict),DecisionBoundaryDisplay.from_estimatoron clustering problems (and possibly link to the inductive clustering example).While none of these are code changes, I think it could still be worth keeping this open until those are done.