teleprocessinggh / check_ai_only.py
winsweb's picture
fix AI model
892b85b
Raw History Blame Contribute Delete
1.67 kB
"""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