A comprehensive framework for robust outlier detection with uncertainty estimation, designed specifically for business intelligence applications.
This system combines multiple detection methods with uncertainty quantification to provide reliable anomaly detection for production environments. It includes statistical baselines, model-based detectors, density-based methods, and intelligent score fusion.
The main production-ready notebook with comprehensive business intelligence features:
- Multi-method outlier detection (Statistical, Model-based, Density-based)
- Score fusion and uncertainty estimation
- Complete benchmarking and evaluation framework
- Unit testing and production recommendations
- BI-focused deployment guidance
Foundational notebook demonstrating core concepts:
- Logistic regression baseline and overconfidence issues
- Temperature scaling and calibration techniques
- Bayesian logistic regression for uncertainty quantification
- Educational examples and visualizations
- Python 3.8+
- Jupyter Notebook environment
- Required packages: numpy, pandas, scikit-learn, matplotlib, seaborn, scipy, joblib
- Clone or download the repository
- Install dependencies:
pip install -r requirements.txt - Start with
detection_basics.ipynbfor concepts, thendetection_bi_domain.ipynbfor production
For Production System:
- Open
detection_bi_domain.ipynb - Execute cells sequentially from top to bottom
- Results will be saved to the
results/directory - Models and artifacts will be saved to the
artifacts/directory
For Learning:
- Start with
detection_basics.ipynbto understand fundamentals - Learn about overconfidence, calibration, and Bayesian approaches
- Then proceed to the full production system
- Statistical Baselines: Z-score and IQR-based detection
- Model-Based: Isolation Forest and Local Outlier Factor (LOF)
- Density-Based: Kernel Density Estimation (KDE) and Gaussian Mixture Models (GMM)
- Score Fusion: Weighted combination of all detector outputs
- Reproducible Results: Fixed seeds and data integrity verification
- Comprehensive Evaluation: AUROC, AUPRC, FPR@95TPR, ECE metrics
- Production Ready: Unit tests, monitoring, and deployment guidelines
- BI-Focused: Specific recommendations for business intelligence use cases
outlier-detection/
βββ detection_bi_domain.ipynb # Main production BI system
βββ detection_basics.ipynb # Educational tutorial notebook
βββ artifacts/ # Saved models and data (included in .gitignore)
βββ results/ # Evaluation results and reports
βββ tests/ # Unit tests
βββ README.md # This file
βββ CHANGELOG.md # Project change history
βββ requirements.txt # Python dependencies
- Synthetic 2D dataset with clear IND/OOD separation
- Two interlocking half-circles (moons) for in-distribution data
- Gaussian cluster for out-of-distribution data
- Data integrity verification with SHA256 hashing
- Standardization pipeline with train/validation/test splits
- Prevents data leakage and ensures proper scaling
- Configurable scaling methods (Standard, Robust, MinMax)
- Statistical methods for baseline comparison
- Advanced ML models for complex pattern detection
- Density-based approaches for likelihood estimation
- Hyperparameter optimization where applicable
- Intelligent combination of detector outputs
- Weight optimization using validation data
- Normalized score scaling for fair comparison
- Grid search for optimal fusion parameters
- Multiple metrics for thorough assessment
- Calibration analysis for reliability
- Benchmark comparison across all methods
- Production-ready performance reporting
Results are automatically generated and saved to:
results/benchmarks.csv- Detailed performance metricsresults/data_summary.csv- Dataset statisticsresults/environment_info.json- Reproducibility informationresults/production_recommendations.json- Deployment guidance
- AUROC: Area Under ROC Curve
- AUPRC: Area Under Precision-Recall Curve
- FPR@95TPR: False Positive Rate at 95% True Positive Rate
- ECE: Expected Calibration Error
- Start Conservative: Use 95th percentile thresholds initially
- Monitor Closely: Track false positive rates and business impact
- Human-in-the-Loop: Review high uncertainty cases manually
- Regular Maintenance: Monthly threshold tuning and model updates
- LOW: 75th percentile threshold, 24h review SLA
- MEDIUM: 90th percentile threshold, 4h review SLA
- HIGH: 95th percentile + uncertainty, immediate review
- CRITICAL: 99th percentile, immediate escalation
- Daily anomaly count tracking
- Feature importance analysis
- Model drift detection
- Performance degradation alerts
Run the built-in unit tests:
# Tests are automatically executed in the notebook
# Or run separately: python -m pytest tests/test_outlier_detection.py -vThe notebook includes a complete integration test that verifies:
- Data generation consistency
- Model training pipeline
- Score fusion functionality
- Evaluation metrics calculation
- Implement detector following sklearn-compatible API
- Add to evaluation pipeline in benchmarking section
- Update score fusion system to include new method
- Add unit tests for new functionality
- Adjust contamination parameters in detector initialization
- Update alert severity levels in production recommendations
- Retrain fusion weights with new threshold preferences
- Replace synthetic data generation with your data loading code
- Ensure proper train/validation/test splits
- Update feature engineering pipeline as needed
- Verify data integrity and tracking
- Isolation Forest Paper
- Local Outlier Factor
- Calibration in ML
- Support Vector Machines
- Outlier Detection Survey
- Making better decisions with uncertain data
- Add new detection methods or improvements
- Enhance evaluation metrics
- Improve production deployment tools
- Expand unit test coverage
- Add real-world use case examples
This project is provided as-is for educational and commercial use under the Apache License 2.0.
For questions or issues:
- Check the notebook comments and documentation
- Review the unit tests for usage examples
- Consult the production recommendations for deployment guidance
- Examine the results files for performance insights
Last updated: September 2025 Version: 1.0