-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_decision_stream.py
More file actions
228 lines (179 loc) · 8.52 KB
/
class_decision_stream.py
File metadata and controls
228 lines (179 loc) · 8.52 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import streamlit as st
import matplotlib.pyplot as plt
import warnings
import pandas as pd
import numpy as np
from PIL import Image
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
from math import *
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import plot_tree
from sklearn.model_selection import cross_validate
from sklearn.model_selection import cross_val_score
from class_traintest import OneHotEncoding
from class_base import Base
from pd_download import data_cleaning
from class_missing_values import ImputationCat
from class_decision_tree import DecisionTree
import data_stream
# ---------------------------------------------------------------DecisionStream--------------------------------------------------
class DecisionStream(DecisionTree):
def dec_get_dataset(self, data):
st.dataframe(data)
st.write('Shape of independent variables training dataframe:', data.shape)
def dec_get_perfomance(self, name, x_test_orig, y_test_orig,
ccpalpha, threshold_1, threshold_2):
data = None
if name=='Cross Validation Alpha':
data = super().cross_validate_alphas(ccpalpha)[1]
elif name=='Confusion Matrix':
data = super().dt_pruned_confmatrix(ccpalpha, threshold_1, threshold_2, x_test_orig, y_test_orig)
else:
data = super().dt_pruned_tree(ccpalpha, threshold_1, threshold_2)
return data
def dec_get_prediction(self):
NAME = st.sidebar.text_input("CUSTOMER NAME")
AGE = st.sidebar.slider("AGE", 0,100)
CHILDREN = st.sidebar.slider("CHILDREN", 0, 10)
PERS_H = st.sidebar.slider("PERS_H", 0, 10)
TMADD = st.sidebar.slider("TMADD", 0, 1000)
TMJOB1 = st.sidebar.slider("TMJOB1", 0, 1000)
TEL = st.sidebar.slider("TEL", 1, 10)
NMBLOAN = st.sidebar.slider("NMBLOAN", 0, 10)
FINLOAN = st.sidebar.slider("FINLOAN", 0, 10)
INCOME = st.sidebar.slider("INCOME", 1, 1000000,100)
EC_CARD = st.sidebar.slider("EC_CARD", 1, 10,1)
INC = st.sidebar.slider("INC", 1, 1000000,100)
INC1 = st.sidebar.slider("INC1", 1, 10,1)
BUREAU = st.sidebar.slider("BUREAU", 1, 10,1)
LOCATION = st.sidebar.slider("LOCATION", 1, 10,1)
LOANS = st.sidebar.slider("LOANS", 1, 10,1)
REGN = st.sidebar.slider("REGN", 1, 10,1)
DIV = st.sidebar.slider("DIV", 1, 10,1)
CASH = st.sidebar.slider("CASH", 1, 1000000,100)
# Categorical features
TITLE = st.sidebar.selectbox("TITLE", options=['H','R'])
STATUS = st.sidebar.selectbox("STATUS",options=['V','U','G','E','T','W'])
PRODUCT = st.sidebar.selectbox('PRODUCT',options=['Radio_TV_Hifi','Furniture_Carpet','Dept_Store_Mail'
,'Leisure','Cars','OT']) # dropped Radio
RESID = st.sidebar.selectbox('RESID',options=['Lease','Owner']) # dropped Owner
NAT = st.sidebar.selectbox('NAT',options=['German', 'Turkish','RS', 'Greek' ,'Yugoslav',
'Italian','Other_European','Spanish_Portugue']) #dropped Yugoslavia
PROF = st.sidebar.selectbox('PROF',options=['Others','Civil_Service_M' ,'Self_employed_pe',
'Food_Building_Ca','Chemical_Industr','Pensioner' ,'Sea_Vojage_Gast',
'State_Steel_Ind,','Military_Service']) # dropped State_Steel_Ind
CAR = st.sidebar.selectbox('CAR',options=['Car', 'Without_Vehicle', 'Car_and_Motor_bi']) # dropped Without_Vehicle
CARDS = st.sidebar.selectbox("CARDS",options=['Cheque_card' ,'no_credit_cards', 'Mastercard_Euroc', 'VISA_mybank'
,'VISA_Others','Other_credit_car', 'American_Express']) # dropped cheque card
button_clicked = st.sidebar.button('Submit')
if button_clicked:
R,H = 0,0
if TITLE == 'H':
H=1
# list_.append(H)
else:
R=0
W,V, U, G, E, T = 0,0,0,0,0,0
if STATUS == 'V':
V=1
elif STATUS == 'U':
U=1
elif STATUS == 'G':
G=1
elif STATUS == 'E':
E=1
elif STATUS=='T':
T=1
else:
W = 0
Radio_TV_Hifi, Furniture_Carpet, Dept_Store_Mail, Leisure,Cars, OT = 0,0,0,0,0,0
if PRODUCT=='Furniture_Carpet':
Furniture_Carpet=1
elif PRODUCT=='Dept_Store_Mail':
Dept_Store_Mail=1
elif PRODUCT=='Leisure':
Leisure=1
elif PRODUCT=='Cars':
Cars=1
elif PRODUCT=='OT':
OT=1
else:
Radio_TV_Hifi = 0
Owner,Lease = 0,0
if RESID=='Lease':
Lease=1
else:
Owner=0
Yugoslav,German, Turkish, RS, Greek ,Italian, Other_European, Spanish_Portugue = 0,0,0,0,0,0,0,0
if NAT=='German':
German=1
elif NAT=='Turkish':
Turkish=1
elif NAT=='RS':
RS=1
elif NAT=='Greek':
Greek=1
elif NAT=='Italian':
Italian=1
elif NAT=='Other_European':
Other_European=1
elif NAT=='Spanish_Portugue':
Spanish_Portugue=1
else:
Yugoslav = 1
State_Steel_Ind,Others, Civil_Service_M , Self_employed_pe, Food_Building_Ca, Chemical_Industr\
,Pensioner ,Sea_Vojage_Gast, Military_Service = 0,0,0,0,0,0,0,0,0
if PROF=='Others':
Others=1
elif PROF=='Civil_Service_M':
Civil_Service_M=1
elif PROF=='Self_employed_pe':
Self_employed_pe=1
elif PROF=='Food_Building_Ca':
Food_Building_Ca=1
elif PROF=='Chemical_Industr':
Chemical_Industr=1
elif PROF=='Pensioner':
Pensioner=1
elif PROF=='Sea_Vojage_Gast':
Sea_Vojage_Gast=1
elif PROF=='Military_Service':
Military_Service=1
else:
State_Steel_Ind = 1
Without_Vehicle,Car,Car_and_Motor_bi= 0,0,0
if CAR=='Car':
Car=1
elif CAR=='Car_and_Motor_bi':
Car_and_Motor_bi=1
else:
Without_Vehicle= 1
Cheque_card,no_credit_cards, Mastercard_Euroc, VISA_mybank,VISA_Others\
,Other_credit_car, American_Express = 0,0,0,0,0,0,0
if CARDS=='no_credit_cards':
no_credit_cards=1
elif CARDS=='Mastercard_Euroc':
Mastercard_Euroc=1
elif CARDS == 'VISA_mybank':
VISA_mybank=1
elif CARDS=='VISA_Others':
VISA_Others=1
elif CARDS=='Other_credit_car':
Other_credit_car=1
elif CARDS=='American_Express':
American_Express=1
else:
Cheque_card = 1
inputs1 = [H, R, E, G, T, U, V, W, Cars, Dept_Store_Mail, Furniture_Carpet, Leisure, OT, Radio_TV_Hifi, Lease, Owner
, German, Greek, Italian, Other_European, RS, Spanish_Portugue, Turkish, Yugoslav, Chemical_Industr, Civil_Service_M
, Food_Building_Ca, Military_Service, Others, Pensioner, Sea_Vojage_Gast, Self_employed_pe, State_Steel_Ind
, Car, Car_and_Motor_bi, Without_Vehicle, American_Express, Cheque_card, Mastercard_Euroc, Other_credit_car, VISA_Others
, VISA_mybank, no_credit_cards]
inputs2 = [CHILDREN, PERS_H, AGE, TMADD, TMJOB1, TEL, NMBLOAN, FINLOAN, INCOME, EC_CARD, INC, INC1, BUREAU, LOCATION, LOANS\
, REGN, DIV, CASH]
list_ = inputs2 + inputs1
inputs = np.array([list_]).reshape(1,-1)
answer = data_stream.d.dt_pruned_prediction(data_stream.ccpalpha, data_stream.threshold_1, data_stream.threshold_2,
data_stream.sample, inputs)
st.sidebar.subheader('Customer {} probability of default is: {}'.format(NAME , answer))
st.sidebar.success('Successfully executed the model')