Integrate text_processor with fraud_engine - Hybrid scoring (Step 2/5)
Browse files- fraud_engine.py +17 -3
fraud_engine.py
CHANGED
|
@@ -7,6 +7,7 @@ It coordinates multiple agents and produces the final decision: investigate | al
|
|
| 7 |
import json
|
| 8 |
from typing import Dict, List, Any
|
| 9 |
from datetime import datetime
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
class FraudEngine:
|
|
@@ -15,6 +16,7 @@ class FraudEngine:
|
|
| 15 |
def __init__(self):
|
| 16 |
self.version = "1.0.0"
|
| 17 |
self.decision_threshold = 0.65
|
|
|
|
| 18 |
|
| 19 |
def process_claim(self, claim_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 20 |
"""Process a claim and return fraud decision.
|
|
@@ -27,12 +29,22 @@ class FraudEngine:
|
|
| 27 |
"""
|
| 28 |
# Step 1: Feature Engineering
|
| 29 |
features = self._engineer_features(claim_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Step 2: Multi-Agent Analysis
|
| 32 |
pattern_analysis = self._analyze_patterns(features)
|
| 33 |
anomaly_analysis = self._detect_anomalies(features)
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
# Step 3: Decision Logic
|
| 37 |
decision = self._make_decision(risk_score)
|
| 38 |
|
|
@@ -53,7 +65,9 @@ class FraudEngine:
|
|
| 53 |
"evidence": explainability["evidence"],
|
| 54 |
"confidence": explainability["confidence"],
|
| 55 |
"audit_id": audit_log["audit_id"],
|
| 56 |
-
"timestamp": audit_log["timestamp"]
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
def _engineer_features(self, claim_data: Dict[str, Any]) -> Dict[str, Any]:
|
|
|
|
| 7 |
import json
|
| 8 |
from typing import Dict, List, Any
|
| 9 |
from datetime import datetime
|
| 10 |
+
from text_processor import InsuranceTextProcessor
|
| 11 |
|
| 12 |
|
| 13 |
class FraudEngine:
|
|
|
|
| 16 |
def __init__(self):
|
| 17 |
self.version = "1.0.0"
|
| 18 |
self.decision_threshold = 0.65
|
| 19 |
+
self.text_processor = InsuranceTextProcessor()
|
| 20 |
|
| 21 |
def process_claim(self, claim_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 22 |
"""Process a claim and return fraud decision.
|
|
|
|
| 29 |
"""
|
| 30 |
# Step 1: Feature Engineering
|
| 31 |
features = self._engineer_features(claim_data)
|
| 32 |
+
|
| 33 |
+
# Step 1.5: Text Analysis (Maysat Method)
|
| 34 |
+
text_analysis = None
|
| 35 |
+
if 'claim_description' in claim_data:
|
| 36 |
+
text_analysis = self.text_processor.analyze_claim_text(claim_data['claim_description'])
|
| 37 |
|
| 38 |
# Step 2: Multi-Agent Analysis
|
| 39 |
pattern_analysis = self._analyze_patterns(features)
|
| 40 |
anomaly_analysis = self._detect_anomalies(features)
|
| 41 |
+
# Hybrid scoring: 30% Text + 70% Rules
|
| 42 |
+
rule_score = self._calculate_risk_score(pattern_analysis, anomaly_analysis)
|
| 43 |
+
if text_analysis:
|
| 44 |
+
text_score = text_analysis['fraud_score']
|
| 45 |
+
risk_score = 0.3 * text_score + 0.7 * rule_score
|
| 46 |
+
else:
|
| 47 |
+
risk_score = rule_score
|
| 48 |
# Step 3: Decision Logic
|
| 49 |
decision = self._make_decision(risk_score)
|
| 50 |
|
|
|
|
| 65 |
"evidence": explainability["evidence"],
|
| 66 |
"confidence": explainability["confidence"],
|
| 67 |
"audit_id": audit_log["audit_id"],
|
| 68 |
+
"timestamp": audit_log["timestamp"],
|
| 69 |
+
"text_analysis": text_analysis,
|
| 70 |
+
"method": "Hybrid (Text + Rules)" if text_analysis else "Rule-based only"
|
| 71 |
}
|
| 72 |
|
| 73 |
def _engineer_features(self, claim_data: Dict[str, Any]) -> Dict[str, Any]:
|