From 0015b4b718eeeb9f55eee128d8a14ac2382531e6 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 7 Aug 2024 15:56:59 +0700 Subject: [PATCH] Create local_outlier_factor.py --- .../piguardian/ai_ml/local_outlier_factor.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 projects/piguardian/ai_ml/local_outlier_factor.py 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)