A scikit-learn machine learning pipeline that predicts whether a loan applicant is at risk of defaulting, based on their financial profile and personal details.
This pipeline was trained on 252,000 loan applicant records. It combines a full data preprocessing pipeline with a tuned Random Forest Classifier. The preprocessing handles:
1import joblib
2import pandas as pd
3from huggingface_hub import hf_hub_download
4
5# Download the pipeline from Hugging Face Hub
6model_path = hf_hub_download(
7 repo_id="amanbokaro/loan-default-prediction-pipeline",
8 filename="loan_default_rf_pipeline.joblib"
9)
10
11# Load the pipeline
12pipeline = joblib.load(model_path)
13
14# Example input (single applicant)
15applicant = pd.DataFrame([{
16 "Income": 500000,
17 "Age": 35,
18 "Experience": 8,
19 "Married/Single": "married",
20 "House_Ownership": "rented",
21 "Car_Ownership": "yes",
22 "Profession": "Software_Developer",
23 "CITY": "Mumbai",
24 "STATE": "Maharashtra",
25 "CURRENT_JOB_YRS": 4,
26 "CURRENT_HOUSE_YRS": 3
27}])
28
29# Predict
30prediction = pipeline.predict(applicant)
31probability = pipeline.predict_proba(applicant)
32
33print("Prediction:", "High Risk" if prediction[0] == 1 else "Low Risk")
34print(f"Default probability: {probability[0][1]:.2%}")