Detector API¶
fraud_detection.detector
¶
Main fraud detection orchestrator for insurance claims analysis.
This module provides the central entry point for running fraud detection on insurance claims data. It coordinates multiple detection strategies:
-
Rule-based detection: Identifies known fraud patterns (billing anomalies, geographic impossibilities, suspicious timing).
-
Statistical detection: Finds outliers using Z-score, IQR, and Benford's Law analysis.
-
Duplicate detection: Identifies exact and near-duplicate claims that may indicate double-billing or resubmission schemes.
The results are combined into a composite fraud score that prioritizes claims for investigation based on the number and severity of flags triggered.
Classes¶
DetectionConfig
dataclass
¶
Configuration parameters for fraud detection algorithms.
Controls thresholds, weights, and limits used by all detection components. Default values are tuned for typical healthcare claims data but should be adjusted based on your specific data characteristics and risk tolerance.
Parameters¶
outlier_zscore_threshold : float, default 3.0 Number of standard deviations from mean to flag as outlier. Lower values catch more anomalies but increase false positives. outlier_iqr_multiplier : float, default 1.5 IQR multiplier for outlier bounds. Standard is 1.5 (Tukey's method); use 3.0 for extreme outliers only. duplicate_similarity_threshold : float, default 0.9 Minimum similarity score (0-1) for near-duplicate detection. Higher values require closer matches. duplicate_time_window_days : int, default 30 Maximum days between claims to consider them potential duplicates. max_provider_patient_distance_miles : float, default 500.0 Maximum reasonable distance between patient and provider locations. max_daily_procedures_per_provider : int, default 50 Maximum procedures a provider can reasonably bill in one day. max_claims_per_patient_per_day : int, default 5 Maximum claims expected for a single patient per day. weight_rule_violation : float, default 0.3 Weight for rule violations in composite fraud score. weight_statistical_anomaly : float, default 0.25 Weight for statistical anomalies in composite fraud score. weight_duplicate : float, default 0.45 Weight for duplicate detection in composite fraud score.
Examples¶
Use stricter thresholds for high-value claims¶
config = DetectionConfig( ... outlier_zscore_threshold=2.5, ... duplicate_similarity_threshold=0.85, ... ) detector = FraudDetector(spark, config)
Source code in packages/fraud_detection/src/fraud_detection/detector.py
FraudDetector
¶
Central orchestrator for insurance fraud detection.
Coordinates multiple detection strategies (rule-based, statistical, and duplicate detection) and combines their outputs into a unified fraud score. Designed for distributed processing on large claims datasets using PySpark.
Parameters¶
spark : SparkSession Active Spark session for distributed processing. config : DetectionConfig, optional Configuration object with detection thresholds and weights. If not provided, uses default values.
Attributes¶
billing_rules : BillingPatternRules Component for detecting suspicious billing patterns. duplicate_detector : DuplicateDetector Component for identifying duplicate claims. geographic_rules : GeographicRules Component for detecting geographic anomalies. outlier_detector : OutlierDetector Component for statistical outlier detection. benfords_analyzer : BenfordsLawAnalyzer Component for Benford's Law conformity analysis.
Examples¶
from pyspark.sql import SparkSession spark = SparkSession.builder.appName("FraudDetection").getOrCreate() detector = FraudDetector(spark) results = detector.detect(claims_df) high_risk = results.filter(results.fraud_score > 0.7)
Source code in packages/fraud_detection/src/fraud_detection/detector.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
Functions¶
detect(claims)
¶
Run the complete fraud detection pipeline on claims data.
Executes all detection methods in sequence: rule-based checks, statistical analysis, duplicate detection, then combines results into a weighted fraud score.
Parameters¶
claims : DataFrame Input claims data with required columns:
- ``claim_id`` : str - Unique claim identifier.
- ``patient_id`` : str - Patient identifier.
- ``provider_id`` : str - Provider identifier.
- ``procedure_code`` : str - CPT/HCPCS procedure code.
- ``service_date`` : date - Date of service.
- ``charge_amount`` : decimal - Billed amount.
- ``patient_state`` : str, optional - Patient's state.
- ``provider_state`` : str, optional - Provider's state.
Returns¶
DataFrame Processed claims with fraud analysis results:
- ``claim_id``, ``patient_id``, ``provider_id``, ``charge_amount`` : Original fields.
- ``fraud_score`` : float - Composite risk score (0-1).
- ``fraud_reasons`` : array<str> - List of triggered flags.
- ``rule_violations`` : array<str> - Rule-based flags triggered.
- ``statistical_flags`` : array<str> - Statistical anomaly flags.
- ``is_duplicate`` : bool - Whether claim is a duplicate.
- ``duplicate_of`` : str - Original claim ID if duplicate.
- ``processed_at`` : timestamp - When analysis was performed.