Contamination parameter in LOCI
Created by: shortydips24
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.decision_scores_ > 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 / sigma_mdef 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.