dschandra commited on
Commit
e5ec122
·
verified ·
1 Parent(s): 11e2f00

Update model/anomaly_detector.py

Browse files
Files changed (1) hide show
  1. model/anomaly_detector.py +6 -1
model/anomaly_detector.py CHANGED
@@ -15,7 +15,7 @@ model.fit(train_data)
15
 
16
  def detect_anomaly_plain_text(agent_data):
17
  features = extract_features(agent_data)
18
- prediction = model.predict([features])[0] # -1 is anomaly
19
  flagged = prediction == -1
20
 
21
  reasons = []
@@ -28,6 +28,10 @@ def detect_anomaly_plain_text(agent_data):
28
  reasons.append("a high lead drop rate")
29
  if agent_data["travel_distance"] < 10:
30
  reasons.append("unusual travel distance")
 
 
 
 
31
 
32
  reason_text = (
33
  f"Agent {agent_data['agent_id']} has been flagged for anomalous behavior due to "
@@ -37,3 +41,4 @@ def detect_anomaly_plain_text(agent_data):
37
  )
38
 
39
  return reason_text
 
 
15
 
16
  def detect_anomaly_plain_text(agent_data):
17
  features = extract_features(agent_data)
18
+ prediction = model.predict([features])[0] # -1 = anomaly
19
  flagged = prediction == -1
20
 
21
  reasons = []
 
28
  reasons.append("a high lead drop rate")
29
  if agent_data["travel_distance"] < 10:
30
  reasons.append("unusual travel distance")
31
+
32
+ # 🔧 New fallback reason if no rule matches but model flags it
33
+ if not reasons:
34
+ reasons.append("an unusual behavior pattern detected by the model")
35
 
36
  reason_text = (
37
  f"Agent {agent_data['agent_id']} has been flagged for anomalous behavior due to "
 
41
  )
42
 
43
  return reason_text
44
+