maduekedickson commited on
Commit
0624190
β€’
1 Parent(s): f3c95d9

Create Ml-Model

Browse files

![images.jpeg](https://cdn-uploads.huggingface.co/production/uploads/6610e15c85c0fba509b22155/LPmfmtcMslWw6CfGOPNam.jpeg)

Files changed (1) hide show
  1. Ml-Model +62 -0
Ml-Model 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()