Initial PayGuard fraud detection system implementation
- Complete dual-layer architecture for fraud detection - Phase 1: Docker Compose infrastructure (Kafka, Zookeeper, Redis) - Phase 2: Mock ML models (Layer 1 fast, Layer 2 deep) - Phase 3: FastAPI transaction ingestion with JWT auth - Phase 4: Kafka consumer pipeline with feature extraction - Phase 5: Test transaction producer with demo scenarios - Phase 6: Clean code structure and comprehensive documentation - Phase 7: End-to-end validation and demo readiness Demonstrates key system design patterns: - Microservices architecture with decoupled components - Asynchronous event processing via Kafka - Tiered decision-making (fast path vs deep analysis) - Resilience patterns (circuit breaker for graceful degradation) - Behavioral profiling with Redis caching Ready for academic demonstration with clear pipeline observability. Co-authored-by: Copilot <[email protected]>
This commit is contained in:
commit
aa4dd497e2
24 files changed
+2343
No files matched your search
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
Model definitions for PayGuard fraud detection
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
|
||||
class Layer1MockModel:
|
||||
"""Fast, lightweight model for initial fraud scoring"""
|
||||
|
||||
def predict_proba(self, features):
|
||||
"""
|
||||
Layer 1: Fast model
|
||||
Score < 0.4: Approve
|
||||
Score >= 0.4: Escalate to Layer 2
|
||||
"""
|
||||
amount = features[0][0]
|
||||
avg_amount = features[0][1]
|
||||
|
||||
if avg_amount == 0:
|
||||
ratio = 1.0
|
||||
else:
|
||||
ratio = amount / avg_amount
|
||||
|
||||
fraud_prob = min(0.95, max(0.05, (ratio - 1.0) * 0.2))
|
||||
legit_prob = 1.0 - fraud_prob
|
||||
|
||||
return np.array([[legit_prob, fraud_prob]])
|
||||
|
||||
class Layer2MockModel:
|
||||
"""Deep, complex model for suspicious transactions"""
|
||||
|
||||
def predict_proba(self, features):
|
||||
"""
|
||||
Layer 2: Deep model
|
||||
Score <= 0.7: Approve
|
||||
Score > 0.7: Block
|
||||
"""
|
||||
amount = features[0][0]
|
||||
avg_amount = features[0][1]
|
||||
tx_count = features[0][2]
|
||||
|
||||
fraud_prob = 0.1
|
||||
|
||||
if avg_amount > 0:
|
||||
ratio = amount / avg_amount
|
||||
fraud_prob += (ratio - 1.0) * 0.25
|
||||
|
||||
if tx_count < 3:
|
||||
fraud_prob += 0.2
|
||||
elif tx_count < 10:
|
||||
fraud_prob += 0.1
|
||||
|
||||
fraud_prob = min(0.95, max(0.05, fraud_prob))
|
||||
legit_prob = 1.0 - fraud_prob
|
||||
|
||||
return np.array([[legit_prob, fraud_prob]])
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user