Financial Fraud Detection: Imbalanced Classification
Module: Fintech AI | Difficulty: Advanced
Class Imbalance
Cost-Sensitive Learning
where .
SMOTE
Real-Time Detection
Evaluation
| Metric | Precision | Recall | F1 |
|---|---|---|---|
| Baseline | 0.85 | 0.45 | 0.59 |
| SMOTE | 0.78 | 0.72 | 0.75 |
| XGBoost | 0.82 | 0.68 | 0.74 |
import numpy as np
from sklearn.ensemble import IsolationForest
class FraudDetector:
def __init__(self, contamination=0.01):
self.model = IsolationForest(contamination=contamination)
def fit(self, X):
self.model.fit(X)
def predict(self, X):
scores = self.model.decision_function(X)
return (scores < 0).astype(int)
def real_time_score(self, features, threshold=0.5):
# Lightweight model for real-time
score = self.fast_model.predict_proba(features.reshape(1,-1))[0,1]
return {'fraud_prob': score, 'flagged': score > threshold}
Research Insight: Real-time fraud detection requires sub-100ms latency. Two-stage approaches use a lightweight model for initial screening and a complex model for flagged transactions. Graph neural networks capture fraud patterns in transaction networks.