Kazeemkz commited on
Commit
cbabb00
1 Parent(s): 6d160af

Initial commit of Streamlit loan prediction app

Browse files
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import joblib
5
+
6
+ # Load the trained model and encoders
7
+ loaded_model = joblib.load('loan_prediction_model.joblib')
8
+ label_encoder_education = joblib.load('label_encoder_education.joblib')
9
+
10
+
11
+ # Title of the Streamlit app
12
+ st.title("IntuiPy Loan Default Prediction App")
13
+
14
+ st.write("Enter the details below to predict whether a loan will default or not.")
15
+
16
+ # Function to make predictions based on user input
17
+ def predict_loan_default(user_input):
18
+ # Encode categorical features
19
+ user_input['education'] = label_encoder_education.transform([user_input['education']])[0]
20
+
21
+ # Create DataFrame for prediction
22
+ user_input_df = pd.DataFrame([user_input])
23
+
24
+ # Make prediction
25
+ prediction = loaded_model.predict(user_input_df)
26
+ return prediction[0] # Return the predicted class
27
+
28
+ # Input fields for the user to provide data
29
+ age = st.number_input("Age", min_value=18, max_value=100, value=30)
30
+ education = st.selectbox("Education Level", options=label_encoder_education.classes_)
31
+ loan_amount = st.number_input("Loan Amount", min_value=0, value=5000)
32
+ asset_cost = st.number_input("Asset Cost", min_value=0, value=6000)
33
+ no_of_loans = st.number_input("Number of Loans", min_value=0, value=2)
34
+ no_of_curr_loans = st.number_input("Number of Current Loans", min_value=0, value=1)
35
+ last_delinq_none = st.selectbox("Previously failed to make required payments on time ?(1 for True, 0 for False)", options=[1, 0])
36
+
37
+ # Prepare the input for prediction
38
+ user_input = {
39
+ 'age': age,
40
+ 'education': education,
41
+ #'proof_submitted': proof_submitted,
42
+ 'loan_amount': loan_amount,
43
+ 'asset_cost': asset_cost,
44
+ 'no_of_loans': no_of_loans,
45
+ 'no_of_curr_loans': no_of_curr_loans,
46
+ 'last_delinq_none': last_delinq_none
47
+ }
48
+
49
+ # Predict button
50
+ if st.button("Predict Loan Default"):
51
+ prediction = predict_loan_default(user_input)
52
+ 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) +""
53
+ st.write(f" {result}")
label_encoder_education.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edcf0413eed88edf524b04fb818e191a4705443722a2d6a6383a925ff4df284c
3
+ size 343
loan_prediction_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:70a421df02baea04e746fc6901c1f8a4a2e92c2927d88e756c68e661bea6c4fc
3
+ size 1355
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ joblib