Upload isolation_forest.py
Browse files
models/anomaly_detection/isolation_forest.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sklearn.ensemble import IsolationForest
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
def detect_anomalies_isolation_forest(df, features):
|
5 |
+
model = IsolationForest(n_estimators=100, contamination=0.01)
|
6 |
+
df['anomaly_score'] = model.fit_predict(df[features])
|
7 |
+
df['is_anomaly'] = df['anomaly_score'] == -1
|
8 |
+
return df
|