Twan07 commited on
Commit
22f5471
·
verified ·
1 Parent(s): 001bef4

Create src/security/anomalyEngine.js

Browse files
Files changed (1) hide show
  1. src/security/anomalyEngine.js +13 -0
src/security/anomalyEngine.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import IsolationForest from "ml-isolation-forest";
2
+
3
+ let model = null;
4
+
5
+ export function trainModel(data) {
6
+ model = new IsolationForest({ contamination: 0.02 });
7
+ model.fit(data);
8
+ }
9
+
10
+ export function isAnomaly(vec) {
11
+ if (!model) return false;
12
+ return model.predict([vec])[0] === -1;
13
+ }