Skip to content

Commit

Permalink
Create local_outlier_factor.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent e9245cc commit 0015b4b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions projects/piguardian/ai_ml/local_outlier_factor.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 0015b4b

Please sign in to comment.