mnurbani commited on
Commit
32f44b9
1 Parent(s): 93b76ea

first deploy

Browse files
Files changed (9) hide show
  1. CC.jpeg +0 -0
  2. P1G5_Set_1_mardhya.csv +0 -0
  3. app.py +10 -0
  4. eda.py +55 -0
  5. list_cat_cols.txt +1 -0
  6. list_num_cols.txt +1 -0
  7. model_svm.pkl +3 -0
  8. prediction.py +113 -0
  9. requirements.txt +8 -0
CC.jpeg ADDED
P1G5_Set_1_mardhya.csv ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ page = st.sidebar.selectbox('Pilih Halaman : ', ('EDA', 'Prediction'))
6
+
7
+ if page == 'EDA' :
8
+ eda.run()
9
+ else:
10
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ from PIL import Image
7
+
8
+ def run():
9
+ #Membuat title
10
+ st.title('Credit Cards Simulation')
11
+
12
+ #Tambahkan gambar
13
+ image = Image.open('CC.jpeg')
14
+ st.image(image, caption = 'Credit Cards')
15
+
16
+ #Menambahkan deskripsi
17
+ st.write('Page ini dibuat oleh Mardhya Malik Nurbani')
18
+
19
+ #Membuat garis
20
+ st.markdown('----')
21
+
22
+ #Masukkan pandas dataframe
23
+
24
+ #Show dataframe
25
+ df = pd.read_csv('P1G5_Set_1_mardhya.csv')
26
+ st.dataframe(df)
27
+
28
+ #Membuat bar plot
29
+ # st.write('#### Plot AttackingWorkRate')
30
+ # fig = plt.figure(figsize=(15,5))
31
+ # sns.countplot(x='AttackingWorkRate', data = df)
32
+ # st.pyplot(fig)
33
+
34
+ # #Membuat histogram
35
+ # st.write('#### Histogram of Age')
36
+ # fig = plt.figure(figsize=(15,5))
37
+ # sns.histplot(df['Overall'], bins = 30, kde = True)
38
+ # st.pyplot(fig)
39
+
40
+ # #membuat histogram berdasarkan inputan user
41
+ # st.write('#### Histogram berdasarkan input user')
42
+ # #kalo mau pake radio button, ganti selectbox jadi radio
43
+ # option = st.selectbox('Pilih Column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
44
+ # fig = plt.figure(figsize= (15,5))
45
+ # sns.histplot(df[option], bins = 30, kde = True)
46
+ # st.pyplot(fig)
47
+
48
+ # #Membuat Plotly plot
49
+
50
+ # st.write('#### Plotly Plot - ValueEUR vs Overall')
51
+ # fig = px.scatter(df, x = 'ValueEUR', y = 'Overall', hover_data = ['Name', 'Age'])
52
+ # st.plotly_chart(fig)
53
+
54
+ if __name__ == '__main__':
55
+ run()
list_cat_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ []
list_num_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["limit_balance", "sex", "education_level", "marital_status", "age", "pay_0", "pay_2", "pay_3", "pay_4", "pay_5", "pay_6", "bill_amt_1", "bill_amt_2", "bill_amt_3", "bill_amt_4", "bill_amt_5", "bill_amt_6", "pay_amt_1", "pay_amt_2", "pay_amt_3", "pay_amt_4", "pay_amt_5", "pay_amt_6"]
model_svm.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63e0a4df641d81ccff26ff89e72467ab90030be0a39b977d33a1e7c8b0c7e245
3
+ size 124872
prediction.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import json
6
+
7
+ #Load All Files
8
+
9
+ #load model dan files yang sudah di save pada framing
10
+
11
+ with open('list_num_cols.txt', 'r') as file_1:
12
+ list_num_cols = json.load(file_1)
13
+ with open('list_cat_cols.txt', 'r') as file_2:
14
+ list_cat_cols = json.load(file_2)
15
+ with open('model_svm.pkl', 'rb') as file_3:
16
+ model_svm = pickle.load(file_3)
17
+
18
+ def run():
19
+
20
+ with st.form('credit_cards_simulation'):
21
+ #Field Nama
22
+ LimitBalance = st.number_input('Limit Balance', value = 0)
23
+ #Field Umur
24
+ Sex = st.number_input('Sex', min_value = 1, max_value = 2, value = 1, step = 1, help = '1 = Male, 2 = Female')
25
+ #Field Tinggi badan
26
+ EducationLevel = st.number_input('Education', min_value = 1, max_value = 6, value = 1, step = 1, help = '1 = Graduate School, 2 = University, 3 = High School, 4 = Other, 5 = Unknown, 6 = Unknown')
27
+ #Field Weight
28
+ MaritalStatus = st.number_input('Marital Status', min_value = 1, max_value = 3, value = 1, step = 1, help = '1 = Married, 2 = Single, 3 = Other')
29
+ #field price
30
+ Age = st.slider('Age', 18, 70, 25)
31
+
32
+ st.markdown('----')
33
+
34
+ #Field Attacking Work Rate
35
+ Pay_0 = st.number_input('Pay 1', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment Status in September, 2025 (-2 = No Transaction, -1 = Pay Duly, 1-9 = Payment Delay 1-9 Month)')
36
+ #Field Defensive Work Rate
37
+ Pay_2 = st.number_input('Pay 2', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in August, 2005 (scale same as above)')
38
+ #Field Pace Total
39
+ Pay_3 = st.number_input('Pay 3', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in July, 2005 (scale same as above)')
40
+ #Field Shooting Total
41
+ Pay_4 = st.number_input('Pay 4', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in June, 2005 (scale same as above)')
42
+ #Field Passing Total
43
+ Pay_5 = st.number_input('Pay 5', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in May, 2005 (scale same as above)')
44
+ #Field Dribbling Total
45
+ Pay_6 = st.number_input('Pay 6', min_value = -2, max_value = 9, value = 0, step = 1, help = 'Repayment status in April, 2005 (scale same as above)')
46
+ #Field Defending Total
47
+ Bill_amt_1 = st.number_input('Amount Of Bill 1', value = 0 , help = 'Amount of bill statement in September, 2005 (NT dollar)')
48
+ #Field Physicality Total
49
+ Bill_amt_2 = st.number_input('Amount Of Bill 2', value = 0, help = 'Amount of bill statement in August, 2005 (NT dollar)')
50
+ Bill_amt_3 = st.number_input('Amount Of Bill 3', value = 0, help = 'Amount of bill statement in July, 2005 (NT dollar)')
51
+ Bill_amt_4 = st.number_input('Amount Of Bill 4', value = 0, help = 'Amount of bill statement in June, 2005 (NT dollar)')
52
+ Bill_amt_5 = st.number_input('Amount Of Bill 5', value = 0, help = 'Amount of bill statement in May, 2005 (NT dollar)')
53
+ Bill_amt_6 = st.number_input('Amount Of Bill 6', value = 0, help = 'Amount of bill statement in April, 2005 (NT dollar)')
54
+ #Field Pay AMT
55
+ Pay_amt_1 = st.number_input('Amount of previous payment 1', value = 0, help = 'Amount of previous payment in September, 2005 (NT dollar)')
56
+ Pay_amt_2 = st.number_input('Amount of previous payment 2', value = 0, help = 'Amount of previous payment in August, 2005 (NT dollar)')
57
+ Pay_amt_3 = st.number_input('Amount of previous payment 3', value = 0, help = 'Amount of previous payment in July, 2005 (NT dollar)')
58
+ Pay_amt_4 = st.number_input('Amount of previous payment 4', value = 0, help = 'Amount of previous payment in June, 2005 (NT dollar)')
59
+ Pay_amt_5 = st.number_input('Amount of previous payment 5', value = 0, help = 'Amount of previous payment in May, 2005 (NT dollar)')
60
+ Pay_amt_6 = st.number_input('Amount of previous payment 6', value = 0, help = 'Amount of previous payment in April, 2005 (NT dollar)')
61
+
62
+
63
+ #bikin submit button
64
+ submitted = st.form_submit_button('Predict')
65
+
66
+ #Inference
67
+ data_inf = {
68
+ 'limit_balance': LimitBalance,
69
+ 'sex': Sex,
70
+ 'education_level': EducationLevel,
71
+ 'marital_status': MaritalStatus,
72
+ 'age': Age,
73
+ 'pay_0' : Pay_0,
74
+ 'pay_2' : Pay_2,
75
+ 'pay_3' :Pay_3,
76
+ 'pay_4': Pay_4,
77
+ 'pay_5' : Pay_5,
78
+ 'pay_6' :Pay_6,
79
+ 'bill_amt_1' :Bill_amt_1,
80
+ 'bill_amt_2':Bill_amt_2,
81
+ 'bill_amt_3':Bill_amt_3,
82
+ 'bill_amt_4':Bill_amt_4,
83
+ 'bill_amt_5':Bill_amt_5,
84
+ 'bill_amt_6':Bill_amt_6,
85
+ 'pay_amt_1':Pay_amt_1,
86
+ 'pay_amt_2':Pay_amt_2,
87
+ 'pay_amt_3':Pay_amt_3,
88
+ 'pay_amt_4':Pay_amt_4,
89
+ 'pay_amt_5':Pay_amt_5,
90
+ 'pay_amt_6':Pay_amt_6,
91
+
92
+ }
93
+
94
+ data_inf = pd.DataFrame([data_inf])
95
+ st.dataframe(data_inf)
96
+
97
+ #Logic ketika predic button ditekan
98
+
99
+ if submitted:
100
+ #split between numerical and categorical columns
101
+ data_inf_num = data_inf[list_num_cols]
102
+ data_inf_cat = data_inf[list_cat_cols]
103
+
104
+ #Scaling & Encoding
105
+ data_inf_final = data_inf_num
106
+
107
+ #predict using linear reg model
108
+ y_pred_inf = model_svm.predict(data_inf_final)
109
+
110
+ st.write('## Payment : ', str(int(y_pred_inf)))
111
+
112
+ if __name__ == '__main__':
113
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ numpy
6
+ plotly
7
+ pillow
8
+ scikit-learn==1,2.2