Skip to content

Commit 102663d

Browse files
authored
FIX proper inheritance for SGDOneClassSVM (scikit-learn#30227)
1 parent 70aab36 commit 102663d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- :class:`~sklearn.linear_model.SGDOneClassSVM` now correctly inherits from
2+
:class:`~sklearn.base.OutlierMixin` and the tags are correctly set.
3+
By :user:`Guillaume Lemaitre <glemaitre>`

sklearn/linear_model/_stochastic_gradient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ def __sklearn_tags__(self):
20842084
return tags
20852085

20862086

2087-
class SGDOneClassSVM(BaseSGD, OutlierMixin):
2087+
class SGDOneClassSVM(OutlierMixin, BaseSGD):
20882088
"""Solves linear One-Class SVM using Stochastic Gradient Descent.
20892089
20902090
This implementation is meant to be used with a kernel approximation

sklearn/linear_model/tests/test_sgd.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from sklearn.pipeline import make_pipeline
2121
from sklearn.preprocessing import LabelEncoder, MinMaxScaler, StandardScaler, scale
2222
from sklearn.svm import OneClassSVM
23+
from sklearn.utils import get_tags
2324
from sklearn.utils._testing import (
2425
assert_allclose,
2526
assert_almost_equal,
@@ -2170,3 +2171,12 @@ def test_passive_aggressive_deprecated_average(Estimator):
21702171
est = Estimator(average=0)
21712172
with pytest.warns(FutureWarning, match="average=0"):
21722173
est.fit(X, Y)
2174+
2175+
2176+
def test_sgd_one_class_svm_estimator_type():
2177+
"""Check that SGDOneClassSVM has the correct estimator type.
2178+
2179+
Non-regression test for if the mixin was not on the left.
2180+
"""
2181+
sgd_ocsvm = SGDOneClassSVM()
2182+
assert get_tags(sgd_ocsvm).estimator_type == "outlier_detector"

0 commit comments

Comments
 (0)