Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated fit_predict & fit_predict_score #617

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions pyod/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from scipy.stats import binom
from sklearn.metrics import roc_auc_score
from sklearn.preprocessing import MinMaxScaler
from sklearn.utils import deprecated
from sklearn.utils.multiclass import check_classification_targets
from sklearn.utils.validation import check_is_fitted
from scipy.optimize import root_scalar
Expand Down Expand Up @@ -108,35 +107,6 @@ def decision_function(self, X):
"""
pass

@deprecated()
def fit_predict(self, X, y=None):
"""Fit detector first and then predict whether a particular sample
is an outlier or not. y is ignored in unsupervised models.

Parameters
----------
X : numpy array of shape (n_samples, n_features)
The input samples.

y : Ignored
Not used, present for API consistency by convention.

Returns
-------
outlier_labels : numpy array of shape (n_samples,)
For each observation, tells whether
it should be considered as an outlier according to the
fitted model. 0 stands for inliers and 1 for outliers.

.. deprecated:: 0.6.9
`fit_predict` will be removed in pyod 0.8.0.; it will be
replaced by calling `fit` function first and then accessing
`labels_` attribute for consistency.
"""

self.fit(X, y)
return self.labels_

def predict(self, X, return_confidence=False):
"""Predict if a particular sample is an outlier or not.

Expand Down Expand Up @@ -488,51 +458,6 @@ def _predict_rank(self, X, normalized=False):
ranks = ranks / ranks.max()
return ranks

@deprecated()
def fit_predict_score(self, X, y, scoring='roc_auc_score'):
"""Fit the detector, predict on samples, and evaluate the model by
predefined metrics, e.g., ROC.

Parameters
----------
X : numpy array of shape (n_samples, n_features)
The input samples.

y : Ignored
Not used, present for API consistency by convention.

scoring : str, optional (default='roc_auc_score')
Evaluation metric:

- 'roc_auc_score': ROC score
- 'prc_n_score': Precision @ rank n score

Returns
-------
score : float

.. deprecated:: 0.6.9
`fit_predict_score` will be removed in pyod 0.8.0.; it will be
replaced by calling `fit` function first and then accessing
`labels_` attribute for consistency. Scoring could be done by
calling an evaluation method, e.g., AUC ROC.
"""

self.fit(X)

if scoring == 'roc_auc_score':
score = roc_auc_score(y, self.decision_scores_)
elif scoring == 'prc_n_score':
score = precision_n_scores(y, self.decision_scores_)
else:
raise NotImplementedError('PyOD built-in scoring only supports '
'ROC and Precision @ rank n')

print("{metric}: {score}".format(metric=scoring, score=score))

return score


def _set_n_classes(self, y):
"""Set the number of classes if `y` is presented, which is not
expected. It could be useful for multi-class outlier detection.
Expand Down
28 changes: 0 additions & 28 deletions pyod/test/test_abod.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_model_clone(self):
clone_clf = clone(self.clf)

Expand Down Expand Up @@ -216,20 +202,6 @@ def test_prediction_proba_linear_confidence(self):
assert (confidence.min() >= 0)
assert (confidence.max() <= 1)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

# def test_score(self):
# self.clf.score(self.X_test, self.y_test)
# self.clf.score(self.X_test, self.y_test, scoring='roc_auc_score')
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_ae1svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ def test_prediction_proba_linear_confidence(self):
assert confidence.min() >= 0
assert confidence.max() <= 1

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_prediction_with_rejection(self):
pred_labels = self.clf.predict_with_rejection(self.X_test,
return_stats=False)
Expand All @@ -117,16 +113,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_model_clone(self):
# for deep models this may not apply
clone_clf = clone(self.clf)
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_alad.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_prediction_scores_with_sigmoid(self):
self.alad = ALAD(activation_hidden_gen='sigmoid',
activation_hidden_disc='sigmoid')
Expand Down
13 changes: 0 additions & 13 deletions pyod/test/test_auto_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,6 @@ def test_prediction_with_rejection_stats(self):
self.assertLessEqual(ub_rejrate, 1)
self.assertGreaterEqual(ub_cost, 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
self.assertEqual(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
self.assertRaises(NotImplementedError, self.clf.fit_predict_score,
self.X_test, self.y_test, scoring='something')

def tearDown(self):
pass

Expand Down
7 changes: 0 additions & 7 deletions pyod/test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@ def test_fit(self):
self.dummy_clf = Dummy2()
assert_equal(self.dummy_clf.fit(0), 0)

def test_fit_predict(self):
# TODO: add more testcases

self.dummy_clf = Dummy3()

assert_equal(self.dummy_clf.fit_predict(0), 0)

def test_predict_proba(self):
# TODO: create uniform testcases
pass
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_cblof.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_predict_rank(self):
pred_socres = self.clf.decision_function(self.X_test)
pred_ranks = self.clf._predict_rank(self.X_test)
Expand Down
28 changes: 0 additions & 28 deletions pyod/test/test_cof.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_predict_rank(self):
pred_scores = self.clf.decision_function(self.X_test)
pred_ranks = self.clf._predict_rank(self.X_test)
Expand Down Expand Up @@ -223,20 +209,6 @@ def test_prediction_proba_parameter(self):
with assert_raises(ValueError):
self.clf.predict_proba(self.X_test, method='something')

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_predict_rank(self):
pred_scores = self.clf.decision_function(self.X_test)
pred_ranks = self.clf._predict_rank(self.X_test)
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_copod.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_predict_rank(self):
pred_socres = self.clf.decision_function(self.X_test)
pred_ranks = self.clf._predict_rank(self.X_test)
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_copod_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_predict_rank(self):
pred_socres = self.clf.decision_function(self.X_test)
pred_ranks = self.clf._predict_rank(self.X_test)
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_deepsvdd.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_model_clone(self):
clone_clf = clone(self.clf)
clone_clf = clone(self.clf_ae)
Expand Down
4 changes: 0 additions & 4 deletions pyod/test/test_devnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train, self.y_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
Expand Down
14 changes: 0 additions & 14 deletions pyod/test/test_dif.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,6 @@ def test_prediction_with_rejection_stats(self):
assert (ub_rejrate <= 1)
assert (ub_cost >= 0)

def test_fit_predict(self):
pred_labels = self.clf.fit_predict(self.X_train)
assert_equal(pred_labels.shape, self.y_train.shape)

def test_fit_predict_score(self):
self.clf.fit_predict_score(self.X_test, self.y_test)
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='roc_auc_score')
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='prc_n_score')
with assert_raises(NotImplementedError):
self.clf.fit_predict_score(self.X_test, self.y_test,
scoring='something')

def test_model_clone(self):
pass

Expand Down
Loading
Loading