-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalOutlierFactor.py
More file actions
32 lines (23 loc) · 866 Bytes
/
LocalOutlierFactor.py
File metadata and controls
32 lines (23 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from sklearn.neighbors import LocalOutlierFactor
import pandas as pd
import numpy as np
import csv
def load_data():
file_name = "" # .csv INPUT
training_f = open(file_name, "r")
training_csvReader = csv.reader(training_f)
next(training_csvReader) # Remove First Row
total_node = list(training_csvReader)
for i in range(len(total_node)) :
total_node[i].pop(0)
total_node = np.array(total_node, dtype=np.float64)
print(total_node)
return total_node
# fit the model for outlier detection (default : n_neighbors=3, contamination=0.1)
clf = LocalOutlierFactor(n_neighbors=3, contamination=0.1)
y_pred = clf.fit_predict(load_data())
X_scores = clf.negative_outlier_factor_
X_scores = np.array(X_scores, dtype=np.float64)
print(-X_scores)
df = pd.DataFrame(-X_scores)
df.to_csv('',index=False) # .csv OUPUT