diff --git a/projects/piguardian/ai_ml/local_outlier_factor.py b/projects/piguardian/ai_ml/local_outlier_factor.py new file mode 100644 index 000000000..ad780233d --- /dev/null +++ b/projects/piguardian/ai_ml/local_outlier_factor.py @@ -0,0 +1,23 @@ +import numpy as np +from sklearn.neighbors import LocalOutlierFactor + +class LocalOutlierFactorAnomalyDetector: + def __init__(self, n_neighbors=20, algorithm='auto', leaf_size=30, metric='minkowski', p=2): + self.n_neighbors = n_neighbors + self.algorithm = algorithm + self.leaf_size = leaf_size + self.metric = metric + self.p = p + self.lof = LocalOutlierFactor(n_neighbors=n_neighbors, algorithm=algorithm, leaf_size=leaf_size, metric=metric, p=p) + + def fit(self, X): + self.lof.fit(X) + + def predict(self, X): + return self.lof.predict(X) + + def decision_function(self, X): + return self.lof.decision_function(X) + + def score_samples(self, X): + return self.lof.score_samples(X)