Skip to content

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhao062 authored and yuezhao@cs.toronto.edu committed Jun 15, 2018
1 parent 5cef84a commit a278a73
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 12 deletions.
27 changes: 16 additions & 11 deletions pyod/models/base.py
Expand Up @@ -137,23 +137,24 @@ def clone(estimator, safe=True):


def _pprint(params, offset=0, printer=repr):
# noinspection PyPep8
"""Pretty print the dictionary 'params'
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
and sklearn/base.py for more information.
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
and sklearn/base.py for more information.
:param params: The dictionary to pretty print
:type params: dict
:param params: The dictionary to pretty print
:type params: dict
:param offset: The offset in characters to add at the begin of each line.
:type offset: int
:param offset: The offset in characters to add at the begin of each line.
:type offset: int
:param printer: The function to convert entries to strings, typically
the builtin str or repr
:type printer: callable
:param printer: The function to convert entries to strings, typically
the builtin str or repr
:type printer: callable
:return: None
"""
:return: None
"""

# Do a multi-line justified repr:
options = np.get_printoptions()
Expand Down Expand Up @@ -469,6 +470,7 @@ def _process_decision_scores(self):

# noinspection PyMethodParameters
def _get_param_names(cls):
# noinspection PyPep8
"""Get parameter names for the estimator
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
Expand Down Expand Up @@ -500,6 +502,7 @@ def _get_param_names(cls):
return sorted([p.name for p in parameters])

def get_params(self, deep=True):
# noinspection PyPep8
"""Get parameters for this estimator.
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
Expand Down Expand Up @@ -537,6 +540,7 @@ def get_params(self, deep=True):
return out

def set_params(self, **params):
# noinspection PyPep8
"""Set the parameters of this estimator.
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
Expand Down Expand Up @@ -576,6 +580,7 @@ def set_params(self, **params):
return self

def __repr__(self):
# noinspection PyPep8
"""
See http://scikit-learn.org/stable/modules/generated/sklearn.base.BaseEstimator.html
and sklearn/base.py for more information.
Expand Down
1 change: 0 additions & 1 deletion pyod/models/combination.py
Expand Up @@ -90,7 +90,6 @@ def aom(scores, n_buckets=5, method='static', bootstrap_estimators=False,
random_state=random_state)
scores_aom[:, i] = np.max(scores[:, ind], axis=1)


elif method == 'dynamic': # random bucket size
for i in range(n_buckets):
# the number of estimators in a bucket should be 2 - n/2
Expand Down
1 change: 1 addition & 0 deletions pyod/models/knn.py
Expand Up @@ -16,6 +16,7 @@


class KNN(BaseDetector):
# noinspection PyPep8
"""kNN class for outlier detection.
For an observation, its distance to its kth nearest neighbor could be
viewed as the outlying score. It could be viewed as a way to measure
Expand Down
1 change: 1 addition & 0 deletions pyod/models/lof.py
Expand Up @@ -16,6 +16,7 @@


class LOF(BaseDetector):
# noinspection PyPep8
"""Wrapper of scikit-learn LOF Class with more functionalities.
Unsupervised Outlier Detection using Local Outlier Factor (LOF).
Expand Down
1 change: 1 addition & 0 deletions pyod/models/pca.py
Expand Up @@ -19,6 +19,7 @@


class PCA(BaseDetector):
# noinspection PyPep8
"""
Principal component analysis (PCA) can be used in detecting outliers. PCA
is a linear dimensionality reduction using Singular Value Decomposition
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_abod.py
Expand Up @@ -10,6 +10,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_combination.py
Expand Up @@ -11,6 +11,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils import shuffle
from sklearn.utils.testing import assert_equal
from sklearn.utils.testing import assert_array_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_feature_bagging.py
Expand Up @@ -11,6 +11,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_hbos.py
Expand Up @@ -10,6 +10,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_iforest.py
Expand Up @@ -11,6 +11,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_knn.py
Expand Up @@ -11,6 +11,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_lof.py
Expand Up @@ -10,6 +10,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_mcd.py
Expand Up @@ -10,6 +10,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_ocsvm.py
Expand Up @@ -11,6 +11,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_pca.py
Expand Up @@ -10,6 +10,7 @@
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_array_less
from sklearn.utils.testing import assert_equal
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_stat_models.py
Expand Up @@ -14,6 +14,7 @@

import unittest
from sklearn.utils.testing import assert_equal
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_less_equal
from sklearn.utils.testing import assert_raises
Expand Down
1 change: 1 addition & 0 deletions pyod/test/test_utility.py
Expand Up @@ -14,6 +14,7 @@

import unittest
from sklearn.utils.testing import assert_equal
# noinspection PyProtectedMember
from sklearn.utils.testing import assert_allclose
from sklearn.utils.testing import assert_less_equal
from sklearn.utils.testing import assert_raises
Expand Down
1 change: 1 addition & 0 deletions pyod/utils/stat_models.py
Expand Up @@ -19,6 +19,7 @@


def wpearsonr(x, y, w=None):
# noinspection PyPep8
"""
Utility function to calculate the weighted Pearson correlation of two
samples.
Expand Down

0 comments on commit a278a73

Please sign in to comment.