Skip to content

Commit d06cb61

Browse files
committed
depreciate behaviour value instead of default
1 parent d2fbc4e commit d06cb61

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

doc/whats_new/v0.20.rst

+2
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,8 @@ Outlier Detection models
868868
used.
869869
In the new behaviour the ``decision_function`` is dependent on the ``contamination``
870870
parameter, in such a way that 0 becomes its natural threshold to detect outliers.
871+
Setting behaviour to "old" is deprecated and will not be possible in version 0.22.
872+
Beside, the behaviour parameter will be removed in 0.24.
871873
:issue:`11553` by `Nicolas Goix`_.
872874

873875
Covariance

sklearn/ensemble/iforest.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class IsolationForest(BaseBagging, OutlierMixin):
9191
9292
behaviour : str, optional (default='old')
9393
Accepted values are 'old' or 'new'. Behaviour of the decision_function.
94-
Default "behaviour" parameter will change to "new" in version 0.22.
94+
Setting behaviour to "old" is deprecated and will not be possible
95+
in version 0.22.
96+
Beside, the behaviour parameter will be removed in 0.24.
9597
Passing behaviour="new" makes the decision_function change to match
9698
other anomaly detection algorithm API, as explained in details in the
9799
offset_ attribute documentation. Basically, the decision_function
@@ -202,9 +204,9 @@ def fit(self, X, y=None, sample_weight=None):
202204
self._contamination = self.contamination
203205

204206
if self.behaviour == 'old':
205-
warnings.warn('Default "behaviour" parameter will change to "new" '
206-
'in version 0.22. Passing behaviour="new" makes '
207-
'IsolationForest decision_function change to match '
207+
warnings.warn('behaviour="old" is deprecated and will be removed '
208+
'in version 0.22. Please use behaviour="new", which '
209+
'makes the decision_function change to match '
208210
'other anomaly detection algorithm API.',
209211
FutureWarning)
210212

sklearn/ensemble/tests/test_iforest.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_iforest():
6666

6767
@pytest.mark.filterwarnings('ignore:default contamination')
6868
@pytest.mark.filterwarnings('ignore:threshold_ attribute')
69-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
69+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
7070
def test_iforest_sparse():
7171
"""Check IForest for various parameter settings on sparse input."""
7272
rng = check_random_state(0)
@@ -96,7 +96,7 @@ def test_iforest_sparse():
9696

9797
@pytest.mark.filterwarnings('ignore:default contamination')
9898
@pytest.mark.filterwarnings('ignore:threshold_ attribute')
99-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
99+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
100100
def test_iforest_error():
101101
"""Test that it gives proper exception on deficient input."""
102102
X = iris.data
@@ -141,7 +141,7 @@ def test_iforest_error():
141141

142142

143143
@pytest.mark.filterwarnings('ignore:default contamination')
144-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
144+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
145145
def test_recalculate_max_depth():
146146
"""Check max_depth recalculation when max_samples is reset to n_samples"""
147147
X = iris.data
@@ -151,7 +151,7 @@ def test_recalculate_max_depth():
151151

152152

153153
@pytest.mark.filterwarnings('ignore:default contamination')
154-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
154+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
155155
def test_max_samples_attribute():
156156
X = iris.data
157157
clf = IsolationForest().fit(X)
@@ -169,7 +169,7 @@ def test_max_samples_attribute():
169169

170170
@pytest.mark.filterwarnings('ignore:default contamination')
171171
@pytest.mark.filterwarnings('ignore:threshold_ attribute')
172-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
172+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
173173
def test_iforest_parallel_regression():
174174
"""Check parallel regression."""
175175
rng = check_random_state(0)
@@ -195,7 +195,7 @@ def test_iforest_parallel_regression():
195195

196196

197197
@pytest.mark.filterwarnings('ignore:default contamination')
198-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
198+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
199199
def test_iforest_performance():
200200
"""Test Isolation Forest performs well"""
201201

@@ -238,7 +238,7 @@ def test_iforest_works():
238238

239239

240240
@pytest.mark.filterwarnings('ignore:default contamination')
241-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
241+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
242242
def test_max_samples_consistency():
243243
# Make sure validated max_samples in iforest and BaseBagging are identical
244244
X = iris.data
@@ -248,7 +248,7 @@ def test_max_samples_consistency():
248248

249249
@pytest.mark.filterwarnings('ignore:default contamination')
250250
@pytest.mark.filterwarnings('ignore:threshold_ attribute')
251-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
251+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
252252
def test_iforest_subsampled_features():
253253
# It tests non-regression for #5732 which failed at predict.
254254
rng = check_random_state(0)
@@ -274,7 +274,7 @@ def test_iforest_average_path_length():
274274

275275

276276
@pytest.mark.filterwarnings('ignore:default contamination')
277-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
277+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
278278
def test_score_samples():
279279
X_train = [[1, 1], [1, 2], [2, 1]]
280280
clf1 = IsolationForest(contamination=0.1).fit(X_train)
@@ -288,7 +288,7 @@ def test_score_samples():
288288

289289

290290
@pytest.mark.filterwarnings('ignore:default contamination')
291-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
291+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
292292
def test_deprecation():
293293
X = [[0.0], [1.0]]
294294
clf = IsolationForest()
@@ -299,7 +299,7 @@ def test_deprecation():
299299
clf.fit, X)
300300

301301
assert_warns_message(FutureWarning,
302-
'Default "behaviour" parameter will change to "new" '
302+
'behaviour="old" is deprecated and will be removed '
303303
'in version 0.22',
304304
clf.fit, X)
305305

@@ -311,7 +311,7 @@ def test_deprecation():
311311

312312

313313
@pytest.mark.filterwarnings('ignore:default contamination')
314-
@pytest.mark.filterwarnings('ignore:Default "behaviour"')
314+
@pytest.mark.filterwarnings('ignore:behaviour="old"')
315315
def test_behaviour_param():
316316
X_train = [[1, 1], [1, 2], [2, 1]]
317317
clf1 = IsolationForest(behaviour='old').fit(X_train)

0 commit comments

Comments
 (0)