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.45k stars 1.36k forks source link

Contamination parameter in LOCI #194

Open shortydips24 opened 4 years ago

shortydips24 commented 4 years ago

Testing multiple values of the contamination parameter yielded the same percentage of outliers (~13%). Review of the source code describes the contamination parameter used in the threshold. However, when looking at the source code for the threshold, the contamination parameter is set to k and does not use the contamination parameter. The contamination parameter is defined in the function as a parameter but not called at any point during the source code.

threshold_ : float The threshold is based on contamination. It is the n_samples * contamination most abnormal samples in decision_scores_. The threshold is calculated for generating binary outlier labels.

self.threshold_ = k

self.labels_ = (self.decisionscores > self.threshold_).astype('int').ravel()

Therefore, the number of outliers is defined only by the value of k, and not the contamination parameter. The % of outliers generated does not match the expected % of outliers.

One other finding of note, when looking at the function _calculate_decision_score, outlier scores are only generated for a hardcoded value of n_hat: if n_hat >= 20: outlier_scores[p_ix] = mdef / sigmamdef if mdef > (self.threshold * sigma_mdef):

Current logic does not seem to output outlier_scores when n_hat <20. Authors should consider parameterizing this value with n_hat having a default of >= 20 or to throw an error message when n_hat is not >=20.

NeighborhoodCoding commented 4 years ago

can i use LOCI? my LOCI() print the error so i can't use it. T.T

yzhao062 commented 4 years ago

I guess there is a bug in the current LOCI code and it is also extremely slow. This is developed by another developer, need to investigate

NeighborhoodCoding commented 4 years ago

Hi, I'm studying outlier detection, can i detect the fraction of outlier(100% no base parameter, 100% data only base)? proximity based algorithm is maybe one solution....(Isolation Forest...?)

NeighborhoodCoding commented 4 years ago

I developed some automatic outlier fraction detection system with one assumption(only one dense cluster is exist even if there may exist very small and dense sub-cluster near by). It searches dense cluster automatically(even though, this automatic outlier fraction is not general and need fine-tuning for raw-data).