File size: 1,669 Bytes
892b85b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Verify AI-only mode (run_anomaly_detection=False, use_model=True):
- detect_anomalies should run only the iforest, no rule detectors.
- Every row in the response should carry has_anomaly=YES with a method
  starting "AI:".
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))

from telecom_anomaly.core.detector import TelecomAnomalyDetector
from telecom_anomaly.core.models import TelecomConfig

CSV = (
    r"C:\my_project\work\GH_Police\main project\backend"
    r"\telecom_anomaly_detection\data\strictly_cleaned_data"
    r"\591296805 calls (1)_strictly_cleaned.csv"
)

cfg = TelecomConfig()
det = TelecomAnomalyDetector(cfg)
det.load_data([CSV])

# AI-only mode
det.detect_anomalies(use_model=True, run_rules=False)
stats = det.get_statistics()

print("=== AI-only mode (run_rules=False, use_model=True) ===")
print(f"Total anomalies: {stats.total_anomalies_detected}")
print(f"Rows with anomalies: {stats.rows_with_anomalies}")
print(f"anomaly_types (should be AI: only): {stats.anomaly_types}")

# Confirm no rule detector fired
rule_method_seen = any(
    not m.startswith('AI:')
    for methods in det.row_anomaly_map.values()
    for m in methods
)
print(f"Any non-AI method fired? {rule_method_seen}")

# Show that 5 sample rows would land with has_anomaly=YES in the response
print("\nSample of 5 flagged rows (these would have has_anomaly=YES):")
shown = 0
for orig_idx, methods in det.row_anomaly_map.items():
    if shown >= 5:
        break
    row = det.original_data[orig_idx]
    has_anomaly = "YES" if methods else "NO"
    print(f"  row {orig_idx}: has_anomaly={has_anomaly} methods={methods}")
    shown += 1