File size: 2,219 Bytes
60a3063
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
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)