I am trying to use sklearn.cluster.OPTICS to identify outliers, but found an issue:
I use 2 examples with exactly the same data but different orders. They give different results:
- 1st example //////////////////////////////////////////// from sklearn.cluster import OPTICS import pandas as pd import numpy as np X = np.array([[1], [2], [3],[1],[8], [8], [7], [100] ])
clust = OPTICS(min_samples=3, metric='euclidean',).fit(X) clust.labels_ //////////////////////////////////////////// output: array([0, 0, 0, 0, 1, 1, 1, 1])
- 2nd example //////////////////////////////////////////// from sklearn.cluster import OPTICS import pandas as pd import numpy as np X = np.array([[1], [2], [3],[8], [8], [7], [100],[1] ])
clust = OPTICS(min_samples=3, metric='euclidean',).fit(X) clust.labels_ //////////////////////////////////////////// output: array([ 0, 0, 0, 1, 1, 1, -1, 0])
We can see X has the same data but different orders. The 2nd output is supposed to be correct as [100] should be an outlier. But oddly, if we change the order of the data, the model gave wrong results.
Can anyone help?
thanks
Ya