From 722514fcdd9a93628131efca2d04bad1fd86ce87 Mon Sep 17 00:00:00 2001 From: Himanshu Aggarwal Date: Wed, 20 Nov 2024 19:54:44 +0100 Subject: [PATCH] Use the estimator type tags as required by scikit-learn 1.6.0 (#4774) --- nilearn/decoding/decoder.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/nilearn/decoding/decoder.py b/nilearn/decoding/decoder.py index 8390f42a58..e806462bbc 100644 --- a/nilearn/decoding/decoder.py +++ b/nilearn/decoding/decoder.py @@ -25,7 +25,12 @@ from packaging.version import parse from sklearn import __version__ as sklearn_version from sklearn import clone -from sklearn.base import BaseEstimator, MultiOutputMixin +from sklearn.base import ( + BaseEstimator, + ClassifierMixin, + MultiOutputMixin, + RegressorMixin, +) from sklearn.dummy import DummyClassifier, DummyRegressor from sklearn.linear_model import ( LassoCV, @@ -1125,7 +1130,7 @@ def __sklearn_tags__(self): @fill_doc -class Decoder(_BaseDecoder): +class Decoder(ClassifierMixin, _BaseDecoder): """A wrapper for popular classification strategies in neuroimaging. The `Decoder` object supports classification methods. @@ -1281,9 +1286,16 @@ def __init__( n_jobs=n_jobs, ) + def __sklearn_tags__(self): + tags = super().__sklearn_tags__() + ver = parse(sklearn_version) + if ver.release[1] >= 6: + tags.estimator_type = "classifier" + return tags + @fill_doc -class DecoderRegressor(MultiOutputMixin, _BaseDecoder): +class DecoderRegressor(MultiOutputMixin, RegressorMixin, _BaseDecoder): """A wrapper for popular regression strategies in neuroimaging. The `DecoderRegressor` object supports regression methods. @@ -1451,6 +1463,8 @@ def __sklearn_tags__(self): if ver.release[1] < 6: return {"multioutput": True} tags = super().__sklearn_tags__() + if ver.release[1] >= 6: + tags.estimator_type = "regressor" tags.target_tags.required = True return tags