File size: 2,188 Bytes
cbabb00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb8d442
 
cbabb00
fb8d442
cbabb00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# app.py
import streamlit as st
import pandas as pd
import joblib

# Load the trained model and encoders
loaded_model = joblib.load('loan_prediction_model.joblib')
label_encoder_education = joblib.load('label_encoder_education.joblib')


# Title of the Streamlit app
st.title("IntuiPy Loan Default Prediction App")

st.write("Enter the details below to predict whether a loan will default or not.")

# Function to make predictions based on user input
def predict_loan_default(user_input):
    # Encode categorical features
    user_input['education'] = label_encoder_education.transform([user_input['education']])[0]

    # Create DataFrame for prediction
    user_input_df = pd.DataFrame([user_input])

    # Make prediction
    prediction = loaded_model.predict(user_input_df)
    return prediction[0]  # Return the predicted class

# Input fields for the user to provide data
age = st.number_input("Age", min_value=18, max_value=100, value=30)
education = st.selectbox("Highest Education (1 for Secondary, 2 for Undergrad)", options=label_encoder_education.classes_)
loan_amount = st.number_input("Requested Loan Amount", min_value=0, value=5000)
asset_cost = st.number_input("Asset Cost", min_value=0, value=6000)
no_of_loans = st.number_input("Loans collected to date", min_value=0, value=2)
no_of_curr_loans = st.number_input("Number of Current Loans", min_value=0, value=1)
last_delinq_none = st.selectbox("Previously failed to make required payments on time ?(1 for True, 0 for False)", options=[1, 0])

# Prepare the input for prediction
user_input = {
    'age': age,
    'education': education,
    #'proof_submitted': proof_submitted,
    'loan_amount': loan_amount,
    'asset_cost': asset_cost,
    'no_of_loans': no_of_loans,
    'no_of_curr_loans': no_of_curr_loans,
    'last_delinq_none': last_delinq_none
}

# Predict button
if st.button("Predict Loan Default"):
    prediction = predict_loan_default(user_input)
    result = "There is a likelihood of default. We regret to inform you that we cannot grant your loan" if prediction == 1 else "We are pleased to inform you that you will not default. We will be sending #" +str(loan_amount) +""
    st.write(f" {result}")