Instructions to use Nestifytech/p2p-MLP-lending-risk-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Scikit-learn
How to use Nestifytech/p2p-MLP-lending-risk-model with Scikit-learn:
from huggingface_hub import hf_hub_download import joblib model = joblib.load( hf_hub_download("Nestifytech/p2p-MLP-lending-risk-model", "sklearn_model.joblib") ) # only load pickle files from sources you trust # read more about it here https://skops.readthedocs.io/en/stable/persistence.html - Notebooks
- Google Colab
- Kaggle
P2P Lending MLP Digital Brain
This repository contains a Multilayer Perceptron (MLP) model, along with Logistic Regression and Random Forest baselines, designed to predict the risk of loan default in a peer-to-peer (P2P) lending context. The models are trained on a subset of the Lending Club dataset.
Model Architecture (MLP Digital Brain)
The MLP model uses the following architecture:
Loan Features โ Dense(64) โ ReLU โ Dense(32) โ ReLU โ Sigmoid โ P(Default)
Features
The models use the following features to predict loan risk:
loan_amnt: The amount of the loan applied for.annual_inc: The annual income of the borrower.dti: Debt-to-income ratio.int_rate: The interest rate on the loan.grade: The loan grade assigned by Lending Club (categorical).
Target Variable
The target variable is loan_status mapped to risk:
0: Fully Paid1: Charged Off
Performance Metrics
The models were evaluated on a test set (20% of the data) with the following metrics. Note that the MLP model uses a custom threshold (0.20) to maximize F1-score on the validation set, while baselines use a default threshold of 0.50.
Validation Metrics
{
"Logistic Regression": {
"ROC-AUC": 0.734351,
"PR-AUC": 0.392071,
"Accuracy": 0.678738,
"Precision": 0.323171,
"Recall": 0.666667,
"F1": 0.435318
},
"Random Forest": {
"ROC-AUC": 0.676701,
"PR-AUC": 0.332663,
"Accuracy": 0.767523,
"Precision": 0.359155,
"Recall": 0.320755,
"F1": 0.33887
},
"MLP Digital Brain": {
"ROC-AUC": 0.734171,
"PR-AUC": 0.375425,
"Accuracy": 0.815421,
"Precision": 0.555556,
"Recall": 0.031447,
"F1": 0.059524
}
}
Test Metrics
{
"Logistic Regression": {
"ROC-AUC": 0.733922,
"PR-AUC": 0.372299,
"Accuracy": 0.674766,
"Precision": 0.32304,
"Recall": 0.683417,
"F1": 0.43871,
"Threshold": 0.5
},
"Random Forest": {
"ROC-AUC": 0.701048,
"PR-AUC": 0.320653,
"Accuracy": 0.754206,
"Precision": 0.346154,
"Recall": 0.361809,
"F1": 0.353808,
"Threshold": 0.5
},
"MLP Digital Brain": {
"ROC-AUC": 0.739213,
"PR-AUC": 0.397156,
"Accuracy": 0.679439,
"Precision": 0.327751,
"Recall": 0.688442,
"F1": 0.444084,
"Threshold": 0.2
}
}
Usage
The model can be used to predict the probability of a loan being charged off and to classify the loan as 'Fully Paid' or 'Charged Off' based on the features.
from huggingface_hub import HfApi
import joblib
import pandas as pd
repo_id = "Nestifytech/p2p-MLP-lending-risk-model"
api = HfApi()
# Download artifacts
api.hf_hub_download(repo_id=repo_id, filename="artifacts/p2p_lending_mlp_digital_brain.joblib", local_dir=".")
api.hf_hub_download(repo_id=repo_id, filename="artifacts/p2p_lending_mlp_metadata.json", local_dir=".")
# Load the model and metadata
loaded_mlp = joblib.load("artifacts/p2p_lending_mlp_digital_brain.joblib")
with open("artifacts/p2p_lending_mlp_metadata.json", "r") as f:
metadata = json.load(f)
best_threshold = metadata["threshold"]
def digital_brain_predict(loan_amnt, annual_inc, dti, int_rate, grade):
row = pd.DataFrame([{ "loan_amnt": loan_amnt, "annual_inc": annual_inc, "dti": dti, "int_rate": int_rate, "grade": grade, }])
p_default = float(loaded_mlp.predict_proba(row)[0, 1])
label = "Charged Off" if p_default >= best_threshold else "Fully Paid"
return { "label": label, "p_charged_off": p_default, "p_fully_paid": 1 - p_default, "threshold": best_threshold }
# Example prediction
prediction = digital_brain_predict(10000, 60000, 15.0, 12.0, "C")
print(prediction)
Demo
A Gradio-based interactive demo for this model is available, allowing users to input loan details and get real-time risk predictions.
Environment
- Python version: 3.13.15
- Pandas version: 3.0.6
- NumPy version: 2.5.3
License
- Downloads last month
- -