FinSight is an end-to-end fintech data science project for credit default prediction, explainable risk review, collections prioritization, API serving, model monitoring, and dashboard-ready reporting. It is designed as a company-neutral portfolio project for credit-risk and collections analytics.
reports/github_polish_checklist.md— final GitHub safety, rendering, links, commands, and push-ready checklist.reports/github_repository_presentation.md— repository description, topics, visibility, and README first-screen check.reports/final_case_study.md— end-to-end business case study.reports/final_project_audit.md— strict final audit, rating, checklist, and production caveats.reports/model_card.md— model card with validation, calibration, explainability, proxy-risk, leakage, and monitoring.reports/governance_checklist.md— production-readiness and deployment controls.reports/fair_lending_review.md— formal fair-lending/proxy-risk governance review without legal-certification claims.CHANGELOG.md— release-history style summary of project maturity milestones.
Digital lenders need to identify applicants who are likely to default, understand why they are risky, and prioritize high-risk accounts for review or collections. A useful credit-risk workflow needs more than a model score: it needs feature pipelines, validation, explainability, monitoring, and business-facing outputs.
FinSight answers:
Which applicants are most likely to default, what risk drivers explain the prediction, and how should collections teams prioritize action?
The project uses the Home Credit Default Risk dataset to build a production-style machine learning workflow:
- validate raw lending data without modifying it
- analyze default behavior with Python and SQL
- engineer applicant-level features with PySpark
- train and validate baseline and final classifiers
- explain global and applicant-level risk with SHAP
- convert predictions into collections risk bands and priority scores
- serve predictions through FastAPI
- monitor drift, missingness, prediction movement, and performance
- generate dashboard-ready CSV files for Power BI
data/raw/*.csv
|
v
src/data/load_data.py -> reports/data_schema_summary.md
src/data/eda_utils.py -> reports/eda_summary.md, reports/figures/
src/data/create_duckdb.py + sql/ -> reports/sql_analysis_summary.md
|
v
src/features/pyspark_feature_engineering.py
-> data/processed/model_features.parquet
-> reports/feature_engineering_summary.md
|
v
src/models/train_baseline.py -> reports/model_comparison.csv, models/*.joblib
src/models/train_final_model.py -> models/credit_risk_model.pkl, final metrics
|
+--> src/explainability/shap_reason_codes.py -> SHAP plots, reason codes
+--> src/business/collections_scoring.py -> risk bands, priority queue
+--> src/api/main.py -> FastAPI prediction service
+--> src/monitoring/evidently_monitoring.py -> drift and quality reports
+--> dashboard/build_dashboard_data.py -> Power BI-ready CSV files
The project uses the Home Credit Default Risk dataset stored locally under data/raw/. Raw data is ignored by Git and is never modified by project scripts.
Expected local files:
application_train.csvHomeCredit_columns_description.csvbureau.csvbureau_balance.csvprevious_application.csvinstallments_payments.csvPOS_CASH_balance.csvcredit_card_balance.csv
The base table is application_train.csv, with TARGET as the binary default label. The processed model table contains 307,511 applicants and 78 columns.
PySpark is used to aggregate multiple Home Credit tables to applicant level (SK_ID_CURR). The pipeline creates lending-risk features including:
- affordability ratios:
credit_to_income_ratio,annuity_to_income_ratio,annuity_to_credit_ratio - applicant stability:
employment_years,age_years - external credit signal aggregates:
external_score_mean,external_score_std - missingness signal:
missing_value_count - bureau history: credit counts, overdue counts, debt-to-credit ratio
- previous application history: prior counts, approved/refused counts, down payment and credit summaries
- repayment behavior: installment delay, late payment count, POS delinquency, credit card balance and DPD signals
- encoded categorical variables for contract type, gender, education, family status, housing type, occupation, and related applicant attributes
Numeric nulls are filled after creating missing_value_count; selected categorical nulls are encoded as Missing.
Generate the feature registry and timestamp-lineage documentation:
python src/features/feature_registry.pyThe command writes:
reports/feature_registry.csvreports/feature_registry.md
The registry documents 76 final model features across application, derived affordability/stability, encoded categorical, bureau, bureau balance, previous application, installment repayment, POS cash, and credit-card feature groups. For each group it records source tables, source columns, transformation logic, join key, aggregation level, availability-time assumptions, leakage risk, owner, and production controls.
Key governance outcome: application-time features are low leakage risk, encoded categorical features require proxy-risk review, and historical bureau/repayment/balance aggregates require source-record timestamp cutoffs before production use.
The project creates a stratified train/validation/test split and handles class imbalance using class weights or scale_pos_weight. Accuracy is not used as the primary metric because defaults are rare and the business task is risk ranking.
Baseline models trained:
- Logistic Regression
- Random Forest
- XGBoost
- LightGBM
LightGBM was selected as the final model because it produced the strongest validation PR-AUC among the baselines. The final model was tuned using validation PR-AUC as the selection metric.
Create MLflow tracking records and registry-style documentation from existing final model artifacts:
python src/models/mlflow_tracking.pyThis command does not retrain the model. It reads reports/final_model_metrics.json, logs parameters, metrics, and report artifacts to MLflow when MLflow is installed, and always writes:
reports/mlflow_experiment_summary.mdreports/model_registry.mdreports/model_registry.json
Local MLflow UI:
mlflow ui --backend-store-uri sqlite:///mlruns/mlflow.dbThe local mlruns/ tracking store is ignored by Git. The script uses a local SQLite backend at sqlite:///mlruns/mlflow.db to avoid MLflow's deprecated filesystem tracking backend.
Final model: tuned LightGBM classifier.
| split | ROC-AUC | PR-AUC | Precision | Recall | F1 | Recall@Top-10% | KS | Brier |
|---|---|---|---|---|---|---|---|---|
| validation | 0.7799 | 0.2712 | 0.2941 | 0.3644 | 0.3255 | 0.3644 | 0.4194 | 0.1643 |
| test | 0.7765 | 0.2640 | 0.2908 | 0.3577 | 0.3208 | 0.3593 | 0.4123 | 0.1645 |
Operational threshold: validation top 10% risk cutoff at score 0.697372.
The model is best interpreted as a risk-ranking and prioritization model. Calibration should be reviewed before using raw probabilities for strict policy thresholds.
Generate the reject inference methodology note:
python src/models/reject_inference.pyThe command writes:
reports/reject_inference_note.mdreports/reject_inference_methodology.json
This analysis does not invent rejected-applicant labels and does not retrain the model. It explains accepted-applicant bias, why rejected-applicant outcomes are missing, how that affects interpretation, and which production methods would be considered before real lending deployment, including parceling, fuzzy augmentation, bureau outcome matching, controlled exploration, and two-stage selection modeling.
Run stratified K-fold validation around the selected LightGBM configuration:
python src/models/cross_validate_model.pyThe command writes reports/cross_validation_results.csv and reports/cross_validation_summary.md. This phase checks whether ROC-AUC, PR-AUC, Recall@Top-10%, and KS are stable across folds.
Actual 5-fold stability results:
| metric | mean | std | min | max |
|---|---|---|---|---|
| ROC-AUC | 0.7830 | 0.0044 | 0.7782 | 0.7893 |
| PR-AUC | 0.2745 | 0.0074 | 0.2651 | 0.2854 |
| Recall@Top-10% | 0.3646 | 0.0074 | 0.3577 | 0.3772 |
| KS statistic | 0.4276 | 0.0104 | 0.4146 | 0.4419 |
Compare raw final-model probabilities against Platt/sigmoid and isotonic calibration:
python src/models/calibrate_model.pyThe command writes reports/calibration_comparison.csv, reports/calibration_report.md, and reports/figures/calibration_comparison.png. This phase separates ranking quality from probability quality, which matters in credit-risk settings where probabilities may feed policy thresholds or portfolio planning.
Actual test-set calibration results:
| method | Brier | ECE | ROC-AUC | PR-AUC | Recall@Top-10% |
|---|---|---|---|---|---|
| Uncalibrated | 0.1645 | 0.2742 | 0.7765 | 0.2640 | 0.3593 |
| Platt/sigmoid | 0.0669 | 0.0062 | 0.7765 | 0.2640 | 0.3593 |
| Isotonic | 0.0668 | 0.0023 | 0.7760 | 0.2540 | 0.3547 |
These are historical, descriptive comparisons, not a test-based method-selection policy. Platt preserves ranking in this comparison; isotonic trades some ranking resolution for lower Brier error. The API still uses the original champion probabilities. New validation-only calibration selection and retrospective confidence intervals are documented in Statistical Validation.
- Statistical validation: 1,000 paired applicant bootstrap replicates for champion/challenger metrics and their differences; validation-only calibration selection.
- Synthetic experiment: two-proportion hypothesis test, effect size, confidence interval and assumptions. Explicitly simulated; no measured business uplift.
- Databricks setup: SQL/PySpark transformations, training-only imputation, validation-selected logistic regression, MLflow and repeatable job configuration.
- Cloud execution evidence: two reported successful manual Databricks job runs with matching data fingerprints, configurations and metrics.
- Execution checklist: completed statistical analysis and cloud evidence review, with verification limits.
python -m src.models.statistical_validation --bootstrap 1000
python -m src.business.experiment_analysis
python -m src.data.prepare_cloud_sample --limit 20000Two supplied Databricks run records match on all six metrics, the transformed-data fingerprint, declared revision, parameters, versions and split counts. The cloud logistic baseline used 20,000 applicants and 9 features, with 12,000/4,000/4,000 train/validation/test rows. Test ROC-AUC was 0.7209, average precision 0.2010, and Brier score 0.2089. These are separate from the local champion metrics and describe an uncalibrated sample baseline. The user-provided screenshot supports two successful manual jobs; this review did not independently access the workspace. No Azure experience, production deployment or measured business uplift is claimed. Previously inspected local test data remains retrospective evidence.
Run segment-level performance and proxy-risk checks:
python src/models/fairness_analysis.pyThe command writes reports/fairness_proxy_metrics.csv and reports/fairness_proxy_analysis.md. This is not a legal fairness certification; it is a portfolio-grade segment-performance review across age bands, income bands, and encoded categorical proxies for gender, education, family status, and occupation.
Key findings from the current run:
- Highest top-10% review-rate segment:
OCCUPATION_TYPE_idx=13at32.11%, with observed default rate17.15%. - Age band
18-25has top-10% review rate22.50%and observed default rate12.29%. - Encoded gender proxy
CODE_GENDER_idx=1has top-10% review rate14.03%versus7.91%forCODE_GENDER_idx=0. - Segment gaps should trigger deeper fair-lending, policy, and feature-governance review before production use.
Generate the formal fair-lending and proxy-risk governance review:
python src/models/fair_lending_governance.pyThe command writes:
reports/fair_lending_review.mdreports/proxy_feature_controls.csvreports/fair_lending_governance.json
This review uses the existing segment metrics and feature registry to document protected/proxy feature controls, segment-risk interpretation, production sign-off requirements, and compliance-ready limitations. It does not claim legal fair-lending certification, does not approve adverse-action language, does not infer protected-class membership, and does not retrain the model.
Current control summary: 76 model features reviewed; 1 gender proxy feature restricted pending fair-lending approval; 2 age-related features restricted pending policy approval; 5 categorical socioeconomic/employment proxies requiring fair-lending review; 7 region/social-network proxies requiring enhanced review; 32 historical credit-behavior features requiring timestamp controls.
Train and compare a less-sensitive challenger model:
python src/models/challenger_governance.pyThe command writes:
reports/challenger_model_comparison.csvreports/challenger_governance_report.mdreports/challenger_governance.jsonmodels/less_sensitive_challenger_model.pkllocally, ignored by Git
The challenger removes 15 features flagged as restricted, fair-lending-review-required, or enhanced-review proxy features. It keeps 61 lower-risk model features and compares against the saved champion model using actual computed PR-AUC, Recall@Top-10%, KS, Brier score, expected calibration error, and top-10% business capture.
Current result: the challenger reduced protected/proxy exposure with a modest performance tradeoff. Test PR-AUC moved from 0.2640 to 0.2559, Recall@Top-10% moved from 0.3593 to 0.3488, and KS moved from 0.4123 to 0.4013. This is governance evidence for discussing whether the champion's predictive lift justifies stronger fair-lending controls.
Run a feature leakage audit against the saved final model feature list:
python src/features/leakage_checks.pyThe command writes reports/leakage_audit.md. The audit verifies that target and identifier fields are excluded from the model feature list, classifies historical aggregate features as medium-risk timing assumptions, and documents which features require human review before production use.
Current audit result: passed. The saved model uses 76 input features; 0 forbidden target/identifier fields were found, 0 model features were missing from the processed table, 0 high-risk outcome-keyword features were found, and 32 historical aggregate features were flagged as medium-risk timing assumptions. Those medium-risk features should have source-record timestamp filters before production use.
SHAP is used for global feature importance and applicant-level reason codes. The explainability script samples 5,000 processed applicants for SHAP analysis and only generates reason codes from positive SHAP contributions.
Top global model drivers from the SHAP run include:
external_score_meanannuity_to_credit_ratioCODE_GENDER_idxgoods_price_to_credit_ratiopos_cash_avg_installments_futureNAME_EDUCATION_TYPE_idxpos_cash_month_countinstallment_max_payment_delay_daysEXT_SOURCE_1AMT_ANNUITY
Example business reason codes include low external credit score, annuity burden risk signal, prior refused application history, high bureau debt burden, and prior repayment delay.
The collections module converts model predictions into risk bands and a priority score.
Risk bands:
- Low Risk: probability < 0.25
- Medium Risk: 0.25 <= probability < 0.50
- High Risk: 0.50 <= probability < 0.70
- Critical Risk: probability >= 0.70
Priority score:
collections_priority_score =
100 * default_probability * (0.70 + 0.30 * normalized_credit_amount) * risk_band_weight
Risk band weights:
- Low Risk:
0.75 - Medium Risk:
1.00 - High Risk:
1.30 - Critical Risk:
1.60
Portfolio risk-band output:
| risk band | applicants | avg default probability | avg priority score |
|---|---|---|---|
| Low Risk | 125,098 | 0.1422 | 7.9374 |
| Medium Risk | 97,954 | 0.3646 | 27.0545 |
| High Risk | 53,578 | 0.5953 | 57.1230 |
| Critical Risk | 30,881 | 0.7810 | 91.6985 |
Estimate how many defaults and how much credit-exposure proxy the model-ranked queue captures at different review capacities:
python src/business/business_impact.pyThe command writes reports/business_impact_by_threshold.csv and reports/business_impact_summary.md. It uses actual labels and AMT_CREDIT as an exposure proxy, without inventing loss-given-default or recovery-rate assumptions.
Actual review-capacity results:
| review capacity | applicants reviewed | defaults captured | default capture rate | lift vs random |
|---|---|---|---|---|
| Top 5% | 15,376 | 6,715 | 27.05% | 5.41x |
| Top 10% | 30,752 | 10,853 | 43.72% | 4.37x |
| Top 15% | 46,127 | 14,029 | 56.51% | 3.77x |
| Top 20% | 61,503 | 16,376 | 65.97% | 3.30x |
At a 10% review capacity, the model-ranked queue captures 43.72% of observed defaults, compared with about 10% expected from random review.
Start the FastAPI service locally:
uvicorn src.api.main:app --reloadOpen the local API documentation:
http://127.0.0.1:8000/docs
Endpoints:
GET /GET /healthPOST /predictPOST /batch_predictPOST /explainGET /model_info
Docker:
docker build -t finsight-credit-risk .
docker run -p 8000:8000 finsight-credit-riskThe API loads models/credit_risk_model.pkl; it does not retrain the model.
Run production-style batch scoring and privacy-safe audit-log generation:
python src/api/batch_score.py --input data/processed/model_features.parquet --limit 1000The command writes:
reports/batch_scoring_sample.csvreports/prediction_audit_log_sample.csvreports/batch_scoring_schema.jsonreports/batch_scoring_summary.md
The batch scoring layer validates the serving schema, logs model name, model version, model stage, feature count, schema version, request IDs, batch ID, score timestamp, risk band, operational threshold flag, collections priority score, and reason-code fields. The committed audit sample is privacy-safe: applicant identifiers are hashed, raw model feature values are not written, and production log folders are ignored by Git.
Current sample run: 1,000 rows scored, 76 required features validated, 0 missing required features, 0 non-numeric required features, and schema validation status passed.
Review the production readiness runbook before discussing deployment:
reports/production_readiness_runbook.mdreports/production_readiness_checklist.json
The runbook covers deployment steps, batch scoring operations, monitoring cadence, alert thresholds, rollback plan, incident response, retraining triggers, ownership, and the final pre-production sign-off checklist. It is a portfolio-grade production-readiness artifact, not a real lender approval record.
The monitoring phase simulates production by splitting the processed dataset into a reference window and a current window, scoring both windows with the saved model, and comparing feature distributions, missingness, prediction distributions, and labeled performance.
Monitoring results:
- Reference rows:
153,755 - Current rows:
153,756 - Features with PSI >= 0.2:
0 - Features with missingness-rate change >= 5%:
0 - Prediction PSI:
0.000117 - Reference ROC-AUC:
0.8455 - Current ROC-AUC:
0.8432 - Current PR-AUC:
0.3490 - Current Recall@Top-10%:
0.4341
The implementation uses a lightweight custom fallback report because it is stable in the local environment. Evidently is available, but the fallback avoids version-specific API issues.
FinSight includes a professional model card and deployment governance checklist:
reports/model_card.mdreports/governance_checklist.mdreports/fair_lending_review.mdreports/proxy_feature_controls.csvreports/challenger_governance_report.mdreports/challenger_model_comparison.csvreports/batch_scoring_summary.mdreports/prediction_audit_log_sample.csvreports/production_readiness_runbook.mdreports/production_readiness_checklist.json
The model card documents intended use, prohibited use, training data, feature groups, validation metrics, calibration, SHAP explainability, proxy-risk findings, leakage audit results, monitoring plan, limitations, and deployment readiness. The governance checklist translates those sections into concrete production controls for data, features, model validation, fairness review, API deployment, monitoring, rollback, and sign-off. The fair-lending review adds segment-risk interpretation and protected/proxy feature controls without claiming legal certification. The batch scoring artifacts show how prediction logging would capture model metadata and audit fields without exposing raw feature values. The production readiness runbook turns these controls into an operating checklist.
Current governance position: FinSight is a portfolio-ready production-style prototype. It is not production-approved for automated credit decisions without business, risk, legal, compliance, data governance, and MLOps review.
This repo currently uses Power BI-ready CSV outputs instead of Streamlit. Streamlit is not required for the project to be portfolio-ready.
Build dashboard files:
python dashboard/build_dashboard_data.pyGenerated files under dashboard/dashboard_data/:
kpi_summary.csvrisk_band_distribution.csvcollections_priority.csvmodel_performance.csvtop_model_features.csvhigh_risk_segments.csvmonitoring_summary.csv
Recommended dashboard pages:
- Executive KPIs
- Default risk distribution
- Risk band distribution
- Collections priority queue
- High-risk applicant segments
- Model performance
- Top model features
- Monitoring and drift summary
FinSight_Credit_Risk_ML/
├── data/
│ ├── raw/ # local raw CSVs, ignored by Git
│ └── processed/ # derived datasets, ignored by Git
├── notebooks/ # EDA notebooks
├── src/
│ ├── data/ # data loading, EDA, SQL/DuckDB setup
│ ├── features/ # PySpark feature engineering
│ ├── models/ # training, metrics, prediction utility
│ ├── explainability/ # SHAP and reason codes
│ ├── business/ # collections scoring
│ ├── monitoring/ # drift and quality reports
│ └── api/ # FastAPI app
├── sql/ # business SQL queries
├── dashboard/ # dashboard data builder and CSV outputs
├── reports/ # markdown, CSV, figures, and HTML reports
│ ├── final_project_audit.md
│ ├── model_card.md
│ └── governance_checklist.md
├── models/ # trained model artifacts, ignored by Git
├── tests/
├── .github/ # CI, issue templates, PR template
├── Dockerfile
├── LICENSE
├── CHANGELOG.md
├── CONTRIBUTING.md
├── SECURITY.md
├── PROJECT_BRIEF.md
├── ROADMAP.md
└── README.md
Create and activate the environment:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtRun each phase from the VS Code terminal:
python src/data/load_data.py
python src/data/eda_utils.py
python src/data/create_duckdb.py
python src/features/pyspark_feature_engineering.py
python src/features/feature_registry.py
python src/features/leakage_checks.py
python src/models/train_baseline.py
python src/models/train_final_model.py
python src/models/mlflow_tracking.py
python src/models/reject_inference.py
python src/models/fair_lending_governance.py
python src/models/challenger_governance.py
python src/models/cross_validate_model.py
python src/models/calibrate_model.py
python src/models/fairness_analysis.py
python src/explainability/shap_reason_codes.py
python src/business/collections_scoring.py
python src/business/business_impact.py
python src/api/batch_score.py --input data/processed/model_features.parquet --limit 1000
uvicorn src.api.main:app --reload
python src/monitoring/evidently_monitoring.py
python dashboard/build_dashboard_data.pyUseful checks:
python -m compileall src dashboard tests
python src/models/predict.py --input data/processed/model_features.parquet --limit 5The repository includes lightweight CI and local quality commands for GitHub readiness:
make checkThis runs:
python -m compileall src dashboard testspytest -q
GitHub Actions runs the same checks on pushes and pull requests to main.
The test suite covers repository hygiene, raw-data validation helpers, model metrics,
collections scoring logic, prediction utilities, and FastAPI endpoints with a mocked
model service so CI does not require private raw data or trained model artifacts.
Before sharing the repository, review:
reports/github_polish_checklist.mdreports/github_repository_presentation.mdThese files verify README rendering, repository safety, ignored artifacts, final links, command snippets, portfolio presentation, repository description, topics, public/private sharing readiness, and the final push-ready workflow. The checklist also reminds reviewers that raw data, processed data, trained models, local MLflow runs, large HTML reports, virtual environments, and logs are intentionally excluded from Git.
The repo includes standard GitHub maintenance files:
LICENSECHANGELOG.mdCONTRIBUTING.mdSECURITY.md.github/PULL_REQUEST_TEMPLATE.md.github/ISSUE_TEMPLATE/
These files document how the project should be reviewed, changed, and shared without exposing raw data, model artifacts, secrets, or unsupported production claims.
For senior technical review, start with:
reports/final_project_audit.mdreports/github_polish_checklist.mdreports/github_repository_presentation.mdreports/feature_registry.mdreports/reject_inference_note.mdreports/fair_lending_review.mdreports/proxy_feature_controls.csvreports/challenger_governance_report.mdreports/challenger_model_comparison.csvreports/batch_scoring_summary.mdreports/batch_scoring_schema.jsonreports/prediction_audit_log_sample.csvreports/production_readiness_runbook.mdreports/production_readiness_checklist.jsonreports/mlflow_experiment_summary.mdreports/model_registry.mdreports/model_card.mdreports/governance_checklist.mdreports/final_case_study.mdreports/leakage_audit.mdreports/fairness_proxy_analysis.mdCHANGELOG.md
- Built FinSight, an end-to-end credit-risk and collections ML platform using PySpark, SQL, scikit-learn, XGBoost/LightGBM, SHAP, FastAPI, and Docker to predict loan default probability and prioritize high-risk applicants.
- Engineered lending-risk features including credit-to-income ratio, annuity burden, employment stability, external score aggregates, repayment behavior, and bureau-history signals using PySpark pipelines.
- Validated models using ROC-AUC, PR-AUC, Recall@Top-K, KS statistic, calibration curves, and confusion-matrix analysis to select a production-ready credit-risk model.
- Added SHAP-based reason codes and dashboard-ready risk outputs to explain applicant-level default drivers for lending and collections decisions.
- Implemented monitoring reports to track data drift, prediction drift, feature quality, and model performance degradation across simulated production batches.
- The project uses the public Home Credit dataset, not live production lending data or production credit bureau feeds.
- Monitoring is simulated by splitting historical processed data into reference and current windows.
- SHAP applicant-level reason codes are generated for a sample to keep local runtime practical.
- Raw probabilities need further calibration and policy review before use as automated decision thresholds.
- Formal legal fair-lending certification, adverse-action compliance approval, regulatory sign-off, and applied reject inference with compliant rejected-applicant outcomes are outside this portfolio scope but would be required for production deployment.
The full portfolio workflow is implemented: scaffold, data validation, EDA, SQL analysis, PySpark feature engineering, baseline and final modeling, explainability, collections scoring, FastAPI serving, monitoring, dashboard-ready outputs, fair-lending/proxy-risk governance, repository maintenance, reviewer handoff, and final audit documentation.