yzhao062 / pyod

A Python Library for Outlier and Anomaly Detection, Integrating Classical and Deep Learning Techniques
http://pyod.readthedocs.io
BSD 2-Clause "Simplified" License
8.48k stars 1.36k forks source link

Scaler error due to mutable default argument in LUNAR #502

Open Mauradion opened 1 year ago

Mauradion commented 1 year ago

The following script returns a ValueError:

import numpy as np
from pyod.models import lunar

X1 = np.zeros((10, 1))
X2 = np.zeros((10, 2))

m1 = lunar.LUNAR()
m1.fit(X1)
out1 = m1.predict(X1)

m2 = lunar.LUNAR()
m2.fit(X2)
out2 = m2.predict(X2)

out3 = m1.predict(X1)

This is likely due to the fact that the scaler (sklearn.preprocessing.MinMaxScaler()) is a mutable default argument of LUNAR. Proposed solution is to add a deepcopy in the init, such as self.scaler = deepcopy(scaler).

If this is the right change, I am willing to do the PR.