diff --git a/doc/whats_new/upcoming_changes/sklearn.linear_model/30227.fix.rst b/doc/whats_new/upcoming_changes/sklearn.linear_model/30227.fix.rst new file mode 100644 index 0000000000000..d3a76ced7fc6b --- /dev/null +++ b/doc/whats_new/upcoming_changes/sklearn.linear_model/30227.fix.rst @@ -0,0 +1,3 @@ +- :class:`~sklearn.linear_model.SGDOneClassSVM` now correctly inherits from + :class:`~sklearn.base.OutlierMixin` and the tags are correctly set. + By :user:`Guillaume Lemaitre ` \ No newline at end of file diff --git a/sklearn/linear_model/_stochastic_gradient.py b/sklearn/linear_model/_stochastic_gradient.py index 4d924a1ad00a6..d5f2247e2af34 100644 --- a/sklearn/linear_model/_stochastic_gradient.py +++ b/sklearn/linear_model/_stochastic_gradient.py @@ -2084,7 +2084,7 @@ def __sklearn_tags__(self): return tags -class SGDOneClassSVM(BaseSGD, OutlierMixin): +class SGDOneClassSVM(OutlierMixin, BaseSGD): """Solves linear One-Class SVM using Stochastic Gradient Descent. This implementation is meant to be used with a kernel approximation diff --git a/sklearn/linear_model/tests/test_sgd.py b/sklearn/linear_model/tests/test_sgd.py index 6f53d2826cc11..c902de2d66480 100644 --- a/sklearn/linear_model/tests/test_sgd.py +++ b/sklearn/linear_model/tests/test_sgd.py @@ -20,6 +20,7 @@ from sklearn.pipeline import make_pipeline from sklearn.preprocessing import LabelEncoder, MinMaxScaler, StandardScaler, scale from sklearn.svm import OneClassSVM +from sklearn.utils import get_tags from sklearn.utils._testing import ( assert_allclose, assert_almost_equal, @@ -2170,3 +2171,12 @@ def test_passive_aggressive_deprecated_average(Estimator): est = Estimator(average=0) with pytest.warns(FutureWarning, match="average=0"): est.fit(X, Y) + + +def test_sgd_one_class_svm_estimator_type(): + """Check that SGDOneClassSVM has the correct estimator type. + + Non-regression test for if the mixin was not on the left. + """ + sgd_ocsvm = SGDOneClassSVM() + assert get_tags(sgd_ocsvm).estimator_type == "outlier_detector"