Transform loan recovery from reactive collection to intelligent optimization
LoanGuard is an enterprise-grade Decision Intelligence platform that goes beyond prediction to optimize recovery actions. It combines ML-based risk scoring with multi-arm bandits, A/B testing, and causal inference to learn which strategies work best for different borrower profiles.
Traditional ML stops at prediction. Decision Intelligence completes the loop:
flowchart LR
A[Predict<br/>Risk Score] --> B[Recommend<br/>Strategy]
B --> C[Act<br/>Intervene]
C --> D[Learn<br/>Outcomes]
D --> A
style A fill:#6366f1,stroke:#4f46e5,color:#ffffff
style B fill:#8b5cf6,stroke:#7c3aed,color:#ffffff
style C fill:#a855f7,stroke:#9333ea,color:#ffffff
style D fill:#c084fc,stroke:#a855f7,color:#ffffff
| Feature | Description |
|---|---|
| Risk Scoring | Random Forest classifier with 95% confidence intervals |
| Borrower Segmentation | K-Means clustering for actionable risk tiers |
| Explainability | SHAP integration for regulatory compliance |
| Feature | Description |
|---|---|
| Multi-Arm Bandit | Thompson Sampling to optimize strategy selection |
| A/B Testing | Built-in framework with chi-square significance testing |
| Outcome Tracking | Persistent logging to measure real-world impact |
| What-If Simulator | Test interventions before committing resources |
| Causal Analysis | Distinguish correlation from causation |
| Feature | Description |
|---|---|
| Audit Trail | JSONL logging of all predictions and decisions |
| Customer 360 | Complete borrower view with procedural activity history |
Frontend β Streamlit (Modular UI Architecture)
Data β Pandas, NumPy
ML β Scikit-learn (Random Forest, K-Means)
Explainability β SHAP (Shapley Values)
Optimization β Thompson Sampling, Contextual Bandits
Statistics β SciPy (chi-square, beta distributions)
Visualization β Plotly Express & Graph Objects
loanguard/
βββ app.py # Application entry point
βββ config/
β βββ settings.py # Centralized configuration
βββ data/
β βββ loan-recovery.csv # Synthetic loan dataset
β βββ logs/ # Decision audit logs
βββ models/ # Trained model artifacts
βββ scripts/
β βββ generate_data.py # Data generation with correlations
β βββ train_model.py # Model training pipeline
βββ src/
β βββ model.py # Risk & Segment models
β βββ features.py # Feature engineering
β βββ decision_log.py # Audit trail logging
β βββ ab_testing.py # A/B testing framework
β βββ optimizer.py # Multi-arm bandit engine
β βββ ui/
β βββ dashboard.py # Executive overview
β βββ portfolio.py # Loan book management
β βββ risk_engine.py # Statistical analysis
β βββ customer_360.py # Single borrower view
β βββ what_if.py # Scenario simulator
β βββ analytics.py # DI analytics hub
βββ tests/ # Unit tests
- Python 3.9+
# Clone repository
git clone https://github.com/BLShaw/LoanGuard
cd LoanGuard
# Install dependencies
pip install -r requirements.txt
# Generate training data
python scripts/generate_data.py
# Train models
python scripts/train_model.py
# Launch dashboard
streamlit run app.pyReal-time portfolio health with recovery rates and exposure visualization.
Filterable loan book with borrower journey flow diagrams.
Test parameter changes and see predicted impact with confidence intervals.
Track outcomes, run A/B tests, and analyze causal effects.
Single borrower deep-dive with SHAP explanations and activity timeline.
# The optimizer learns which strategies work best
recommendation = optimizer.recommend_action(
risk_score=0.72,
segment="High Loan, High Risk",
explore=True # Balance exploration vs exploitation
)
# Returns: ActionRecommendation(action="Legal Action", confidence=0.85, ...)# Create randomized experiments
test_id = ab_framework.create_test(
test_name="Settlement vs Legal",
strategies=["Settlement Offer", "Legal Action"],
use_thompson_sampling=True # Adaptive allocation
)
# Check significance
significance = ab_framework.calculate_significance(test_id)
# Returns: {'significant': True, 'p_value': 0.023, ...}# Log actual results to measure model performance
logger.record_outcome(
borrower_id="BRW_123",
predicted_risk_score=0.72,
predicted_strategy="Legal Action",
actual_outcome="Fully Recovered",
days_to_resolution=45
)| Metric | Value |
|---|---|
| Risk Model Accuracy | ~85% |
| Feature Correlations | Validated (all signs correct) |
| Confidence Intervals | 95% from tree variance |
- Fork the repository
- Create a feature branch (
git checkout -b feature/NewFeature) - Commit your changes (
git commit -m 'Add NewFeature') - Push to the branch (
git push origin feature/NewFeature) - Open a Pull Request
This project is available under the MIT License.