Credit__app / app.py
zebahgr's picture
Add application file
60a3063
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import base64
import seaborn as sns
import matplotlib.pyplot as plt
st.write("""
# Credit Risk Detection App
""")
url_dataset = f'<a href="Training_Data.csv">Download Dataset CSV File</a>'
st.markdown(url_dataset, unsafe_allow_html=True)
def user_input_features() :
income = st.sidebar.slider('income', 10310, 9999938)
age = st.sidebar.slider('age', 21, 79)
experience = st.sidebar.slider('experience', 0, 20)
married = st.sidebar.slider ('married', 0, 1)
house_ownership = st.sidebar.slider ('house_ownership', 0, 2)
car_ownership = st.sidebar.slider ('car_ownership', 0, 1)
profession = st.sidebar.slider ('profession', 0, 51)
current_job_years = st.sidebar.slider('current_job_years', 0, 14)
current_house_years = st.sidebar.slider('current_house_years', 10, 14)
data = {'income':[income],
'age':[age],
'experience':[experience],
'married': [married],
'house_ownership': [house_ownership],
'car_ownership': [car_ownership],
'profession': [profession],
'current_job_years':[current_job_years],
'current_house_years':[current_house_years]}
features = pd.DataFrame(data)
return features
input_df = user_input_features()
credit_raw = pd.read_csv('Training_Data.csv')
credit_raw.fillna(0, inplace=True)
credit = credit_raw.drop(columns=['risk_flag'])
df = pd.concat([input_df, credit],axis=0)
df = df[:1] # Selects only the first row (the user input data)
df.fillna(0, inplace=True)
features = ['income','age','experience','married','house_ownership','car_ownership','profession','current_job_years',
'current_house_years']
df = df[features]
st.subheader('User Input features')
st.write(df)
load_clf = pickle.load(open('Training_Data.pkl', 'rb'))
detection = load_clf.predict(df)
detection_proba = load_clf.predict_proba(df)
credit_labels = np.array(['Normal', 'Beresiko'])
st.subheader('Detection')
#st.write(detection)
st.write(credit_labels[int(detection)])
st.subheader('Detection Probability')
st.write(detection_proba)
#df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=credit_labels)
#st.write(df_prob)