|
import gradio as gr |
|
import pandas as pd |
|
from sklearn.model_selection import train_test_split |
|
from sklearn.linear_model import LogisticRegression |
|
import warnings |
|
|
|
|
|
warnings.filterwarnings("ignore") |
|
|
|
|
|
df_lending_data = pd.read_csv('Resources/lending_data.csv') |
|
|
|
|
|
y = df_lending_data['loan_status'] |
|
X = df_lending_data.drop(columns=['loan_status']) |
|
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1) |
|
|
|
|
|
model = LogisticRegression(max_iter=200, random_state=1) |
|
model.fit(X_train, y_train) |
|
|
|
|
|
def predict_loan_status(loan_size, interest_rate, borrower_income, debt_to_income, num_of_accounts, derogatory_marks, total_debt): |
|
input_data = pd.DataFrame({ |
|
'loan_size': [loan_size], |
|
'interest_rate': [interest_rate], |
|
'borrower_income': [borrower_income], |
|
'debt_to_income': [debt_to_income], |
|
'num_of_accounts': [num_of_accounts], |
|
'derogatory_marks': [derogatory_marks], |
|
'total_debt': [total_debt] |
|
}) |
|
prediction = model.predict(input_data) |
|
return "Healthy Loan (0)" if prediction[0] == 0 else "High-Risk Loan (1)" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_loan_status, |
|
inputs=[ |
|
gr.Number(label="Loan Size"), |
|
gr.Number(label="Interest Rate"), |
|
gr.Number(label="Borrower Income"), |
|
gr.Number(label="Debt-to-Income Ratio"), |
|
gr.Number(label="Number of Accounts"), |
|
gr.Number(label="Derogatory Marks"), |
|
gr.Number(label="Total Debt"), |
|
], |
|
outputs="text", |
|
title="Loan Status Prediction", |
|
description="Input loan details to predict whether the loan is healthy or high-risk. " |
|
"Explore the project on GitHub [here](https://github.com/thaychansy/credit-risk-classification) " |
|
"and try out other models [here](https://huggingface.co/tchans123)." |
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|