nyomanyudisdeveloper commited on
Commit
71f7546
·
verified ·
1 Parent(s): df1fc61

Upload 7 files

Browse files
Files changed (7) hide show
  1. app.py +10 -0
  2. eda.py +171 -0
  3. list_col_cat.txt +1 -0
  4. list_col_num.txt +1 -0
  5. model_dt.pkl +3 -0
  6. prediction.py +172 -0
  7. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ navigation = st.sidebar.selectbox('Pilih Halaman:', {'EDA':'eda','Prediction':'pred'})
6
+
7
+ if navigation == 'EDA':
8
+ eda.run()
9
+ else:
10
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+
5
+ # This cell is used to make new column called 'group_age'
6
+ def filter_group_age(age):
7
+ if 0 <= age <= 14:
8
+ return "children"
9
+ elif 15 <= age <= 24:
10
+ return "youth"
11
+ elif 25 <= age <= 64:
12
+ return "adults"
13
+ elif age >= 65:
14
+ return "seniors"
15
+ else:
16
+ return "unknown"
17
+
18
+
19
+
20
+ def run():
21
+ st.title('Credit Card Payment Exploration Data Analyst(EDA)')
22
+ st.image('https://www.i1.creditdonkey.com/image/1/[email protected]')
23
+ st.write('This page is made by Yudis Aditya')
24
+ st.markdown('---')
25
+
26
+ # st.write('In this page, I want to show visualization data based on my analyst process about credit card payment. This EDA has information about customer segmentation and customer behaviour')
27
+ # st.link_button('Link dataset','https://console.cloud.google.com/bigquery?p=bigquery-public-data&d=ml_datasets&t=credit_card_default&page=table&project=direct-keel-424102-f5&ws=!1m5!1m4!4m3!1sbigquery-public-data!2sml_datasets!3scredit_card_default')
28
+
29
+
30
+ # df = pd.read_csv('P1G5_Set_1_yudis_aditya.csv')
31
+ # df['group_age'] = df['age'].apply(filter_group_age)
32
+
33
+ # st.write('## Customer Segmentation')
34
+ # st.write('### Distribution Data Age')
35
+ # # This cell is used to create histogram column age
36
+ # data = df['age']
37
+ # fig = plt.figure(figsize=(15,5))
38
+ # plt.hist(x=data)
39
+ # plt.title("Distribution Data Age")
40
+ # plt.show()
41
+ # st.pyplot(plt)
42
+ # st.write("From Graph 'Distribution Data Age' we can see that the most client who use credit card have age around 20 - 40")
43
+
44
+
45
+ # st.write('Based on Standarization Statistic Canada, we can make group of age like this :')
46
+ # st.write('- 0 - 14 = children ')
47
+ # st.write('- 15 - 24 = youth')
48
+ # st.write('- 25 - 64 = adults ')
49
+ # st.write('- more than equal 65 = seniors')
50
+
51
+
52
+ # data = df.groupby('group_age').size()
53
+ # x = data.index
54
+ # y = data.values
55
+ # fig = plt.figure(figsize=(15,5))
56
+ # plt.pie(y,labels=x,autopct='%1.1f%%')
57
+ # plt.title("Pie Chart Data based on Group Age")
58
+ # st.pyplot(plt)
59
+
60
+ # st.write('From Graph "Distribution Data Group Age" we can know that majority significant people who use credit card is in group age adults. and The second is youth but not really significant. And group age "seniors" is rare to use credit card. So i dont recommend to target youth and seniors for promotion')
61
+
62
+
63
+ # st.write('### Distribution Data Marital Status')
64
+ # # This cell is used to create pie graph to know distibution data based on marital_status
65
+ # data = df[df['marital_status'] != 0].groupby('marital_status').size()
66
+ # x = ['married','single','others']
67
+ # y = data.values
68
+
69
+ # fig = plt.figure(figsize=(15,5))
70
+ # plt.pie(y,labels=x,autopct='%1.1f%%')
71
+ # plt.title("Distribution data person based on marital status")
72
+ # st.pyplot(fig)
73
+
74
+ # st.write('From Graph above we can see that person who single is more to use credit card than married. person who has marital_status others has not really significant. So i recommend to make promotion product like accesoris, game, outfit, etc that related for increase status social with using pay credit')
75
+
76
+ # st.write('### Distribution Data Gender')
77
+ # data = df.groupby('sex').size()
78
+ # x = ['male','female']
79
+ # y = data.values
80
+
81
+
82
+ # fig = plt.figure(figsize=(15,5))
83
+ # plt.pie(y,labels=x,autopct='%1.1f%%')
84
+ # plt.title("Distribution data person based on gender")
85
+ # st.pyplot(fig)
86
+
87
+ # st.write('From Graph above we can see that female is more using credit card than male. So we can make promotion for product that used for woman with pay using credit.')
88
+
89
+ # st.write('## Customer Behaviour')
90
+ # st.write('### Total People who pay duly on April - September in 2005')
91
+ # fig = plt.figure(figsize=(15,5))
92
+ # # This cell is used to create line chart to know total status payment duly in 2005
93
+ # data_6 = df[(df['pay_6'] <= 0)][['pay_6']].count()
94
+ # data_5 = df[(df['pay_5'] <= 0)][['pay_5']].count()
95
+ # data_4 = df[(df['pay_4'] <= 0)][['pay_4']].count()
96
+ # data_3 = df[(df['pay_3'] <= 0)][['pay_3']].count()
97
+ # data_2 = df[(df['pay_2'] <= 0)][['pay_2']].count()
98
+ # data_1 = df[(df['pay_0'] <= 0)][['pay_0']].count()
99
+
100
+ # data_input = {
101
+ # 'Apr':data_1.values[0],
102
+ # 'May':data_2.values[0],
103
+ # 'Jun':data_3.values[0],
104
+ # 'July':data_4.values[0],
105
+ # 'August':data_5.values[0],
106
+ # 'Sep':data_6.values[0],
107
+ # }
108
+
109
+ # data_visualize = pd.DataFrame([data_input])
110
+ # data_visualize.values.tolist()[0]
111
+
112
+ # # print(data)
113
+ # x = data_visualize.columns.to_list()
114
+ # y = data_visualize.values.tolist()[0]
115
+
116
+ # plt.plot(x,y)
117
+ # plt.title("Total status payment duly in 2005")
118
+ # st.pyplot(fig)
119
+ # st.write('From Graph above we can know that Total people who pay duly are increased significant from April 2005 until September 2005. It indicate that client has good behaviour to pay their bill, so the way to selection client who can have credit card is already good.')
120
+
121
+ # st.write('### Median Bill Amount on April - September in 2005')
122
+ # fig = plt.figure(figsize=(15,5))
123
+ # # This cell is used to create line chart to know total status payment duly in 2005
124
+ # data_6 = df[['bill_amt_6']].median()
125
+ # data_5 = df[['bill_amt_5']].median()
126
+ # data_4 = df[['bill_amt_4']].median()
127
+ # data_3 = df[['bill_amt_3']].median()
128
+ # data_2 = df[['bill_amt_2']].median()
129
+ # data_1 = df[['bill_amt_1']].median()
130
+
131
+ # data_input = {
132
+ # 'Apr':data_1.values[0],
133
+ # 'May':data_2.values[0],
134
+ # 'Jun':data_3.values[0],
135
+ # 'July':data_4.values[0],
136
+ # 'August':data_5.values[0],
137
+ # 'Sep':data_6.values[0],
138
+ # }
139
+
140
+ # data_visualize = pd.DataFrame([data_input])
141
+ # data_visualize.values.tolist()[0]
142
+
143
+ # # print(data)
144
+ # x = data_visualize.columns.to_list()
145
+ # y = data_visualize.values.tolist()[0]
146
+
147
+ # plt.bar(x,y)
148
+ # plt.title("Median Bill amount from April - September 2005")
149
+ # st.pyplot(fig)
150
+ # st.write('From graph above i use median instead mean because distribution data is not normal. We can see that median bill amount from april until September is decrased. That visualize that most people has decrased bill amount every month, which is good. ')
151
+
152
+ # st.write('### Total people who pay and not pay for next month (October) 2005')
153
+ # fig = plt.figure(figsize=(15,5))
154
+ # data_input = df.groupby(['default_payment_next_month']).size()
155
+
156
+ # x = ['Pay','Not Pay']
157
+ # y = data_input.values
158
+
159
+ # plt.bar(x,y)
160
+ # plt.title('Total people who pay and dont pay on October 2005')
161
+ # st.pyplot(fig)
162
+ # st.write('From Graph above we know that more people pay for next month (October) than not pay. It is good result because that indicate client good behaviour and prove that process selection client who can use credit card is success.')
163
+
164
+ # st.markdown('---')
165
+ # st.write('# Conclusion')
166
+ # st.write('From analysis and creating visualize from my dataset , This is a important point that i can share:')
167
+ # st.write("- For promotion , don't target for group age old and young. And we can make deal promotion with product that focus on increase status life style like accesoris, outfit, etc using credit card. Also deal promotion with product that related with woman like makeup, salon , etc.")
168
+ # st.write('- For April until September 2005, we can see that our client summarize has good behavior because dominant pay dully and decrase bill amount for every month. It is indicate the process selection client who can use credit card is good.')
169
+
170
+ if __name__ == '__main__':
171
+ run()
list_col_cat.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["trt", "oprior", "str2", "strat", "treat"]
list_col_num.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["time", "age", "wtkg", "cd40", "cd420"]
model_dt.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13c57837b30bfb21249ce255057273855c509e31e6d22b98f343c5e619685822
3
+ size 2954592
prediction.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import pickle
4
+ import json
5
+
6
+ with open('list_col_num.txt', 'r') as file_1:
7
+ list_col_num_if = json.load(file_1)
8
+
9
+ with open('list_col_cat.txt', 'r') as file_2:
10
+ list_col_cat_if = json.load(file_2)
11
+
12
+ with open('model_dt.pkl', 'rb') as file_3:
13
+ model_dt = pickle.load(file_3)
14
+
15
+ def get_trt_index(trt):
16
+ if trt == 'ZDV only':
17
+ return 0
18
+ elif trt == 'ZDV + ddl':
19
+ return 1
20
+ elif trt == 'ZDV + Zal':
21
+ return 2
22
+ else:
23
+ return 3
24
+
25
+ def get_yes_no_index(yes_no):
26
+ if yes_no == 'no':
27
+ return 0
28
+ else:
29
+ return 1
30
+
31
+ def get_strat_index(strat):
32
+ if strat == 'Antiretroviral Naive':
33
+ return 1
34
+ elif strat == 'Antiretroviral <= 52 weeks':
35
+ return 2
36
+ else:
37
+ return 3
38
+
39
+ def get_symptom_index(symptom):
40
+ if symptom == 'asymp':
41
+ return 0
42
+ else:
43
+ return 1
44
+
45
+ def get_treat_index(treat):
46
+ if treat == 'ZDV only':
47
+ return 0
48
+ else:
49
+ return 1
50
+
51
+ def get_race_index(race):
52
+ if race == 'White':
53
+ return 0
54
+ else:
55
+ return 1
56
+
57
+ def get_gender_index(gender):
58
+ if gender == 'Female':
59
+ return 0
60
+ else:
61
+ return 1
62
+
63
+ def get_str2_index(str2):
64
+ if str2 == 'naive':
65
+ return 0
66
+ else:
67
+ return 1
68
+
69
+ def run():
70
+ with st.form("prediction_form"):
71
+ st.write('Personal Information')
72
+ time = st.number_input('Input time to failure or censoring', value=100)
73
+ trt = st.selectbox('Select Treatment Indicator ', {'ZDV only','ZDV + ddl','ZDV + Zal','ddl only'},index=0)
74
+ age = st.number_input('Input age in years', value=20)
75
+ wtkg = st.number_input('Input weight in kg', value=40.0)
76
+ hemo = st.selectbox('Is patient has hemophilia ?', {'no','yes'},index=0)
77
+ homo = st.selectbox('Is patient has experience do homosexuality activity ?', {'no','yes'},index=0)
78
+ drugs = st.selectbox('Is patient has history of IV drug use ?', {'no','yes'},index=0)
79
+ karnof = st.number_input('Input Karnofsky score (on scale 0 - 100)', value=40, min_value=0, max_value=100,step=1)
80
+ oprior = st.selectbox('Is patient is Non-ZDV antiretroviral therapy pre-175 ?', {'no','yes'},index=0)
81
+ z30 = st.selectbox('Is patient is ZDV in the 30 days prior to 175 ?', {'no','yes'},index=0)
82
+ preanti = st.number_input('Input days pre-175 anti-retroviral therapy', value=40)
83
+ race = st.selectbox('Input patient race ?', {'White','non-white'},index=0)
84
+ gender = st.selectbox('Select gender ?', {'Female','Male'},index=0)
85
+ str2 = st.selectbox('Input antiretroviral history', {'naive','experienced'},index=0)
86
+ strat = st.selectbox('Input antiretroviral history stratification', {'Antiretroviral Naive','Antiretroviral <= 52 weeks','Antiretroviral > 52 weeks'},index=0)
87
+ symptom = st.selectbox('Input symptomatic indicator', {'asymp','symp'},index=0)
88
+ treat = st.selectbox('Input treatment indicator ', {'ZDV only','others'},index=0)
89
+ offtrt = st.selectbox('Input indicator of off-trt before 96+/-5 weeks ', {'no','yes'},index=0)
90
+ cd40 = st.number_input('Input CD4', value=40.0)
91
+ cd420 = st.number_input('Input CD4 at 20+/-5 weeks', value=40.0)
92
+ cd80 = st.number_input('Input CD8', value=40.0)
93
+ cd820 = st.number_input('Input CD8 at 20+/-5 weeks', value=40.0)
94
+ # limit_balance = st.number_input('Input limit balance', value=10000.0)
95
+ # sex = st.selectbox('Gender', {'Male','Female'},index=0)
96
+
97
+ # marital_status = st.selectbox('Marital Status ', {'Married','Single','Others'},index=0)
98
+ # age = st.number_input('Age', value=20)
99
+
100
+ # st.markdown('---')
101
+ # st.write('Repayment Status')
102
+
103
+ # pay_1 = st.selectbox('RePayment Status September 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
104
+ # pay_2 = st.selectbox('RePayment Status August 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
105
+ # pay_3 = st.selectbox('RePayment Status July 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
106
+ # pay_4 = st.selectbox('RePayment Status June 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
107
+ # pay_5 = st.selectbox('RePayment Status May 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
108
+ # pay_6 = st.selectbox('RePayment Status April 2005 ', {'Pay Duly','Payment delay for one month','Payment delay for two month','Payment delay for three month','Payment delay for four month','Payment delay for five month','Payment delay for six month','Payment delay for seven month','Payment delay for eight month','Payment delay for nine month'},index=0)
109
+
110
+ # st.markdown('---')
111
+ # st.write('Bill Amount')
112
+ # bill_amt_1 = st.number_input('Input Billing Amount September 2005 ', value=10000.0)
113
+ # bill_amt_2 = st.number_input('Input Billing Amount August 2005 ', value=10000.0)
114
+ # bill_amt_3 = st.number_input('Input Billing Amount July 2005 ', value=10000.0)
115
+ # bill_amt_4 = st.number_input('Input Billing Amount June 2005 ', value=10000.0)
116
+ # bill_amt_5 = st.number_input('Input Billing Amount May 2005 ', value=10000.0)
117
+ # bill_amt_6 = st.number_input('Input Billing Amount April 2005 ', value=10000.0)
118
+
119
+ # st.markdown('---')
120
+ # st.write('Amount Previous payment')
121
+ # pay_amt_1 = st.number_input('Amount of previous payment in September 2005 ', value=10000.0)
122
+ # pay_amt_2 = st.number_input('Amount of previous payment in August 2005 ', value=10000.0)
123
+ # pay_amt_3 = st.number_input('Amount of previous payment in July 2005 ', value=10000.0)
124
+ # pay_amt_4 = st.number_input('Amount of previous payment in June 2005 ', value=10000.0)
125
+ # pay_amt_5 = st.number_input('Amount of previous payment in May 2005 ', value=10000.0)
126
+ # pay_amt_6 = st.number_input('Amount of previous payment in April 2005 ', value=10000.0)
127
+
128
+ submitted = st.form_submit_button("Submit")
129
+ st.write("Outside the form")
130
+
131
+ data_inf = {
132
+ 'time': time,
133
+ 'trt' : get_trt_index(trt),
134
+ 'age': age,
135
+ 'wtkg': wtkg,
136
+ 'hemo': get_yes_no_index(hemo),
137
+ 'homo': get_yes_no_index(homo),
138
+ 'drugs': get_yes_no_index(drugs),
139
+ 'karnof': karnof,
140
+ 'oprior': get_yes_no_index(oprior),
141
+ 'z30': get_yes_no_index(z30),
142
+ 'preanti': preanti,
143
+ 'race': get_race_index(race),
144
+ 'gender': get_gender_index(gender),
145
+ 'str2': get_str2_index(str2),
146
+ 'strat': get_strat_index(strat),
147
+ 'symptom': get_symptom_index(symptom),
148
+ 'treat': get_treat_index(treat),
149
+ 'offtrt': get_yes_no_index(offtrt),
150
+ 'cd40':cd40,
151
+ 'cd420':cd420,
152
+ 'cd80':cd80,
153
+ 'cd820':cd820
154
+ }
155
+
156
+ if submitted:
157
+ df = pd.DataFrame([data_inf])
158
+ df[list_col_cat_if] = df[list_col_cat_if].astype(object)
159
+ df = df[list_col_cat_if + list_col_num_if]
160
+
161
+ # Do model predict from data input
162
+ predict_result = model_dt.predict(df)
163
+ if predict_result[0] == 1 :
164
+ predic_result_value = 'yes'
165
+ else:
166
+ predic_result_value = 'no'
167
+ st.write(f'## Is patient infected AIDS: {predic_result_value}')
168
+
169
+
170
+
171
+ if __name__ == '__main__':
172
+ run()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ numpy
6
+ scikit-learn
7
+ plotly