From cbc8c9408c1d37c690fd2daf7fc628e986e0e077 Mon Sep 17 00:00:00 2001 From: yzhao062 Date: Sun, 19 Mar 2023 15:27:15 -0400 Subject: [PATCH] urgent fix for nan in ECOD and COPOD --- CHANGES.txt | 1 + pyod/models/copod.py | 6 +++++- pyod/models/ecod.py | 6 +++++- pyod/version.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index cecfc6bf8..b2ba2b591 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -176,3 +176,4 @@ v<1.0.7>, <12/14/2022> -- Enable automatic thresholding by pythresh (#454). v<1.0.8>, <03/08/2023> -- Improve clone compatibility (#471). v<1.0.8>, <03/08/2023> -- Add QMCD detector (#452). v<1.0.8>, <03/08/2023> -- Optimized ECDF and drop Statsmodels dependency (#467). +v<1.0.9>, <03/19/2023> -- Hot fix for errors in ECOD and COPOD due to the issue of scipy. diff --git a/pyod/models/copod.py b/pyod/models/copod.py index 3286e6d83..3d357fd66 100644 --- a/pyod/models/copod.py +++ b/pyod/models/copod.py @@ -12,7 +12,7 @@ import matplotlib.pyplot as plt import numpy as np from joblib import Parallel, delayed -from scipy.stats import skew +from scipy.stats import skew as skew_sp from sklearn.utils import check_array from .base import BaseDetector @@ -20,6 +20,10 @@ from ..utils.stat_models import column_ecdf +def skew(X, axis=0): + return np.nan_to_num(skew_sp(X, axis=axis)) + + def _parallel_ecdf(n_dims, X): """Private method to calculate ecdf in parallel. Parameters diff --git a/pyod/models/ecod.py b/pyod/models/ecod.py index df00a7c5a..fe278b454 100644 --- a/pyod/models/ecod.py +++ b/pyod/models/ecod.py @@ -13,7 +13,7 @@ import matplotlib.pyplot as plt import numpy as np from joblib import Parallel, delayed -from scipy.stats import skew +from scipy.stats import skew as skew_sp from sklearn.utils import check_array from .base import BaseDetector @@ -21,6 +21,10 @@ from ..utils.stat_models import column_ecdf +def skew(X, axis=0): + return np.nan_to_num(skew_sp(X, axis=axis)) + + def _parallel_ecdf(n_dims, X): """Private method to calculate ecdf in parallel. Parameters diff --git a/pyod/version.py b/pyod/version.py index b8b77cde2..51aef5c17 100644 --- a/pyod/version.py +++ b/pyod/version.py @@ -20,4 +20,4 @@ # Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer. # 'X.Y.dev0' is the canonical version of 'X.Y.dev' # -__version__ = '1.0.8' # pragma: no cover +__version__ = '1.0.9' # pragma: no cover