-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (52 loc) · 1.72 KB
/
app.py
File metadata and controls
64 lines (52 loc) · 1.72 KB
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
55
56
57
58
59
60
61
62
63
64
import streamlit as st
import pandas as pd
import numpy as np
import joblib
# page config
st.set_page_config(
page_title="Loan_Prediction App",
page_icon="🗃️",
layout="wide"
)
@st.cache_resource
def load_model():
return joblib.load("Loan.joblib")
st.title("🗃️ Loan Prediction App")
# ---- Input UI ----
col1, col2 = st.columns(2)
with col1:
LoanId = st.text_input("Loan ID")
Gender = st.selectbox("Gender", ["Male", "Female"])
Martial_Status = st.selectbox("Marital Status", ["Yes", "No"])
Employed = st.selectbox("Employed", ["Yes", "No"])
ApplicantIncome = st.number_input("Applicant Income", min_value=0)
with col2:
CoapplicantIncome = st.number_input("Coapplicant Income", min_value=0)
Loan_Amount = st.number_input("Loan Amount", min_value=0)
Loan_Amount_Term = st.number_input("Loan Amount Term", min_value=0)
Credit_History = st.selectbox("Credit History", [1.0, 0.0])
# ---- Encoding for model ----
def encode_inputs():
gender_map = {"Male": 1, "Female": 0}
yesno_map = {"Yes": 1, "No": 0}
return [
hash(LoanId) % 10000, # convert alphanumeric LoanID -> numeric
gender_map[Gender],
yesno_map[Martial_Status],
yesno_map[Employed],
ApplicantIncome,
CoapplicantIncome,
Loan_Amount,
Loan_Amount_Term,
Credit_History
]
# ---- Predict ----
if st.button("Predict Loan Status", type="primary"):
with st.spinner("Predicting..."):
model = load_model()
features = np.array(encode_inputs()).reshape(1, -1)
prediction = model.predict(features)
if prediction[0] == 1:
st.success("Loan Approved ✅")
else:
st.error("Loan Rejected ❌")