LoanPrediction / app.py
viwiyada's picture
Update app.py
eada2d8
import joblib
import pandas as pd
import streamlit as st
purpose_1 = {'all_other': 1,
'credit_card': 2,
'debt_consolidation': 3,
'educational': 4,
'home_improvement': 5,
'major_purchase': 6,
'small_business': 7,
}
model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
unique_Purpose = unique_values["purpose"]
def main():
st.title("Loan Data")
with st.form("questionaire"):
purpose = st.selectbox("Purpose", options = unique_Purpose )
int_rate = st.slider("The interest rate of the loan", 0.0000,1.0000)
installments = st.number_input("The monthly installments owed")
log_annual_inc = st.number_input("The natural log of the self-reported annual income of the borrower")
dti = st.number_input("The debt to income ratio of the borrower")
fico = st.slider("The FICO credit score of the borrower.", 0,1000)
days_with_cr_line = st.number_input("The number of days the borrower has had a credit line.")
revol_bal = st.number_input("The borrower's revolving balance")
revol_util= st.number_input("The borrower's revolving line utilization rate")
inq_last_6mths= st.slider("The borrower's number of inquiries by creditors in the last 6 months.", 0,100)
delinq_2yrs = st.slider("The number of times the borrower had been 30+ days past due on a payment in the past 2 year", 0,100 )
pub_rec= st.slider("The borrower's number of derogatory public records", 0,100 )
not_fully_paid = st.slider("not fully paid.", 0,100)
# clicked==True only when the button is clicked
clicked = st.form_submit_button("Predict loan")
if clicked:
result=model.predict(pd.DataFrame({"purpose":[purpose_1[purpose]],
"int.rate":[int_rate],
"installment":[installments],
"log.annual.inc":[log_annual_inc],
"dti":[dti],
"fico":[fico],
"days.with.cr.line":[days_with_cr_line],
"revol.bal":[revol_bal],
"revol.util":[revol_util],
"inq.last.6mths":[inq_last_6mths],
"delinq.2yrs":[delinq_2yrs],
"pub.rec":[pub_rec],
"not.fully.paid":[not_fully_paid]}))
# Show prediction
result = 'Pass' if result[0] == 0 else 'Not Pass'
st.success("Your predicted loan is "+result) #แสดงผล
# Run main()
if __name__ == "__main__":
main()