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

Parallelize the fit and decision_function methods of FeatureBagging #197

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Corrected some pep8 related errors
  • Loading branch information
Shihab-Shahriar committed May 24, 2020
commit b99fb0f9f76b0fe0beb0eb944d2985253f1b9b3b
1 change: 0 additions & 1 deletion pyod/models/feature_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ def fit(self, X, y=None):

return self


def decision_function(self, X):
"""Predict raw anomaly score of X using the fitted detector.
The anomaly score of an input sample is computed based on different
Expand Down
22 changes: 13 additions & 9 deletions pyod/test/test_feature_bagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import division
from __future__ import print_function

import os
mport os
import sys

import unittest
Expand Down Expand Up @@ -127,8 +127,9 @@ def test_predict_rank_normalized(self):
assert_array_less(-0.1, pred_ranks)

def test_parallel(self):
feat_bag = FeatureBagging(n_jobs=3,
random_state=42).fit(self.X_train, self.y_train)
feat_bag = FeatureBagging(
n_jobs=3,
random_state=42).fit(self.X_train, self.y_train)

# predict_proba
feat_bag.set_params(n_jobs=1)
Expand All @@ -137,24 +138,27 @@ def test_parallel(self):
y2 = feat_bag.predict_proba(self.X_test)
assert_array_almost_equal(y1, y2)

feat_bag = FeatureBagging(n_jobs=1,
random_state=42).fit(self.X_train, self.y_train)
feat_bag = FeatureBagging(
n_jobs=1,
random_state=42).fit(self.X_train, self.y_train)

y3 = feat_bag.predict_proba(self.X_test)
assert_array_almost_equal(y1, y3)

# decision_function
feat_bag = FeatureBagging(n_jobs=3,
random_state=42).fit(self.X_train, self.y_train)
feat_bag = FeatureBagging(
n_jobs=3,
random_state=42).fit(self.X_train, self.y_train)

feat_bag.set_params(n_jobs=1)
decisions1 = feat_bag.decision_function(self.X_test)
feat_bag.set_params(n_jobs=2)
decisions2 = feat_bag.decision_function(self.X_test)
assert_array_almost_equal(decisions1, decisions2)

feat_bag = FeatureBagging(n_jobs=1,
random_state=42).fit(self.X_train, self.y_train)
feat_bag = FeatureBagging(
n_jobs=1,
random_state=42).fit(self.X_train, self.y_train)

decisions3 = feat_bag.decision_function(self.X_test)
assert_array_almost_equal(decisions1, decisions3)
Expand Down