Spaces:
Sleeping
Sleeping
Commit
β’
72487d7
1
Parent(s):
57fbe1d
Upload 3 files
Browse files- app.py +62 -0
- images.jpeg +0 -0
- random_forest_model.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
st.image('images.jpeg')
|
6 |
+
# Load the pickled model
|
7 |
+
loaded_pickle_model = pickle.load(open("random_forest_model.pkl", "rb"))
|
8 |
+
|
9 |
+
def predict_loan_approval(data):
|
10 |
+
# Use the loaded model to make predictions
|
11 |
+
prediction = loaded_pickle_model.predict(data)
|
12 |
+
return prediction
|
13 |
+
|
14 |
+
def main():
|
15 |
+
st.title("Loan Approval Prediction")
|
16 |
+
|
17 |
+
# Input form for user to enter data
|
18 |
+
st.header("Input Data")
|
19 |
+
gender = st.selectbox("Gender", ["Male", "Female"])
|
20 |
+
married = st.selectbox("Married", ["Yes", "No"])
|
21 |
+
dependents = st.number_input("Dependents", min_value=0, max_value=10, value=0)
|
22 |
+
education = st.selectbox("Education", ["Graduate", "Not Graduate"])
|
23 |
+
self_employed = st.selectbox("Self Employed", ["Yes", "No"])
|
24 |
+
applicant_income = st.number_input("Applicant Income", value=0)
|
25 |
+
coapplicant_income = st.number_input("Coapplicant Income", value=0)
|
26 |
+
loan_amount = st.number_input("Loan Amount", value=0)
|
27 |
+
loan_amount_term = st.number_input("Loan Amount Term", value=0)
|
28 |
+
credit_history = st.selectbox("Credit History", [0.0, 1.0])
|
29 |
+
property_area = st.selectbox("Property Area", ["Urban", "Semiurban", "Rural"])
|
30 |
+
|
31 |
+
# Mapping input values to numerical values
|
32 |
+
gender_map = {'Male': 1, 'Female': 0}
|
33 |
+
married_map = {'Yes': 1, 'No': 0}
|
34 |
+
education_map = {'Graduate': 1, 'Not Graduate': 0}
|
35 |
+
self_employed_map = {'Yes': 1, 'No': 0}
|
36 |
+
property_area_map = {'Urban': 0, 'Semiurban': 1, 'Rural': 2}
|
37 |
+
|
38 |
+
# Create a DataFrame from the input data
|
39 |
+
new_data = pd.DataFrame({
|
40 |
+
'Gender': [gender_map[gender]],
|
41 |
+
'Married': [married_map[married]],
|
42 |
+
'Dependents': [dependents],
|
43 |
+
'Education': [education_map[education]],
|
44 |
+
'Self_Employed': [self_employed_map[self_employed]],
|
45 |
+
'ApplicantIncome': [applicant_income],
|
46 |
+
'CoapplicantIncome': [coapplicant_income],
|
47 |
+
'LoanAmount': [loan_amount],
|
48 |
+
'Loan_Amount_Term': [loan_amount_term],
|
49 |
+
'Credit_History': [credit_history],
|
50 |
+
'Property_Area': [property_area_map[property_area]]
|
51 |
+
})
|
52 |
+
|
53 |
+
# Button to predict loan approval
|
54 |
+
if st.button("Predict Loan Approval"):
|
55 |
+
prediction = predict_loan_approval(new_data)
|
56 |
+
if prediction[0] == 1:
|
57 |
+
st.success("Loan is Approved π")
|
58 |
+
else:
|
59 |
+
st.error("Loan is Rejected π")
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
main()
|
images.jpeg
ADDED
![]() |
random_forest_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c8d7e3e991533b76bd250190a9404edd4b7287d787f5a86351c82facc06ab67c
|
3 |
+
size 2602537
|