mnurbani commited on
Commit
0855a17
1 Parent(s): 9d6e5f7

first deploy

Browse files
Files changed (10) hide show
  1. app.py +10 -0
  2. bola.jpg +0 -0
  3. eda1.py +63 -0
  4. list_cat_cols.txt +1 -0
  5. list_num_cols.txt +1 -0
  6. model_encoder.pkl +3 -0
  7. model_lin_reg.pkl +3 -0
  8. model_scaler.pkl +3 -0
  9. prediction.py +98 -0
  10. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda1
3
+ import prediction
4
+
5
+ page = st.sidebar.selectbox('Pilih Halaman : ', ('EDA', 'Prediction'))
6
+
7
+ if page == 'EDA' :
8
+ eda1.run()
9
+ else:
10
+ prediction.run()
bola.jpg ADDED
eda1.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('FIFA 2022 Player Rating Prediction')
11
+
12
+ #Membuat subheader
13
+ st.subheader('EDA untuk Analisa Dataset FIFA 2022')
14
+
15
+ #Tambahkan gambar
16
+ image = Image.open('bola.jpg')
17
+ st.image(image, caption = 'FIFA 2022')
18
+
19
+ #Menambahkan deskripsi
20
+ st.write('Page ini dibuat oleh Bani')
21
+ st.write('**Mardhya Malik**')
22
+ st.write('*Mardhya Malik*')
23
+ st.write('# Mardhya Malik')
24
+ st.write('## Mardhya Malik')
25
+ st.write('### Mardhya Malik')
26
+
27
+ #Membuat garis
28
+ st.markdown('----')
29
+
30
+ #Masukkan pandas dataframe
31
+
32
+ #Show dataframe
33
+ df = pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
34
+ st.dataframe(df)
35
+
36
+ #Membuat bar plot
37
+ st.write('#### Plot AttackingWorkRate')
38
+ fig = plt.figure(figsize=(15,5))
39
+ sns.countplot(x='AttackingWorkRate', data = df)
40
+ st.pyplot(fig)
41
+
42
+ #Membuat histogram
43
+ st.write('#### Histogram of Rating')
44
+ fig = plt.figure(figsize=(15,5))
45
+ sns.histplot(df['Overall'], bins = 30, kde = True)
46
+ st.pyplot(fig)
47
+
48
+ #membuat histogram berdasarkan inputan user
49
+ st.write('#### Histogram berdasarkan input user')
50
+ #kalo mau pake radio button, ganti selectbox jadi radio
51
+ option = st.selectbox('Pilih Column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
52
+ fig = plt.figure(figsize= (15,5))
53
+ sns.histplot(df[option], bins = 30, kde = True)
54
+ st.pyplot(fig)
55
+
56
+ #Membuat Plotly plot
57
+
58
+ st.write('#### Plotly Plot - ValueEUR vs Overall')
59
+ fig = px.scatter(df, x = 'ValueEUR', y = 'Overall', hover_data = ['Name', 'Age'])
60
+ st.plotly_chart(fig)
61
+
62
+ if __name__ == '__main__':
63
+ run()
list_cat_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["AttackingWorkRate", "DefensiveWorkRate"]
list_num_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["Age", "Height", "Weight", "Price", "PaceTotal", "ShootingTotal", "PassingTotal", "DribblingTotal", "DefendingTotal", "PhysicalityTotal"]
model_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e95575e4f4325a8b2cc3751e09de7f29dec00be64588df3e060c44b17ef7e3d
3
+ size 572
model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:61b5177c7282ce0ad6f60601b1b9c4b0e3b25ea7fb558db8f240077726a5b47a
3
+ size 595
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:886a94e22bb659265592ec555c491e70ab234b9e3aa33b0f2546b5d69ea2f0e6
3
+ size 1096
prediction.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ with open('list_num_cols.txt', 'r') as file_1:
10
+ list_num_col = json.load(file_1)
11
+
12
+ with open('list_cat_cols.txt', 'r') as file_2:
13
+ list_cat_col = json.load(file_2)
14
+
15
+ with open('model_scaler.pkl', 'rb') as file_3:
16
+ model_scaler = pickle.load(file_3)
17
+
18
+ with open('model_encoder.pkl', 'rb') as file_4:
19
+ model_encoder = pickle.load(file_4)
20
+
21
+ with open('model_lin_reg.pkl', 'rb') as file_5:
22
+ model_lin_reg = pickle.load(file_5)
23
+
24
+ def run():
25
+
26
+ with st.form('form_fifa_2022'):
27
+ #Field Nama
28
+ name = st.text_input('Name', value = '')
29
+ #Field Umur
30
+ age = st.number_input('Age', min_value = 16, max_value = 60, value = 25, step = 1, help = 'Usia Pemain')
31
+ #Field Tinggi badan
32
+ height = st.slider('Height', 100, 250, 170)
33
+ #Field Weight
34
+ weight = st.number_input('weight', 50, 150, 70)
35
+ #field price
36
+ price = st.number_input('Price', value = 0)
37
+
38
+ st.markdown('----')
39
+
40
+ #Field Attacking Work Rate
41
+ attacking_work_rate = st.selectbox('Attacking Work Rate', ('Low', 'Medium', 'High'), index = 1)
42
+ #Field Defensive Work Rate
43
+ devensive_work_rate = st.selectbox('Devensive Work Rate', ('Low', 'Medium', 'High'), index = 1)
44
+ #Field Pace Total
45
+ pace_total = st.number_input('Pace', min_value = 0, max_value=100, value = 50)
46
+ #Field Shooting Total
47
+ shooting_total = st.number_input('Shooting', min_value = 0, max_value=100, value = 50)
48
+ #Field Passing Total
49
+ passing_total = st.number_input('Passing', min_value = 0, max_value=100, value = 50)
50
+ #Field Dribbling Total
51
+ dribbling_total = st.number_input('Dribbling', min_value = 0, max_value=100, value = 50)
52
+ #Field Defending Total
53
+ defending_total = st.number_input('Defending', min_value = 0, max_value=100, value = 50)
54
+ #Field Physicality Total
55
+ physicality = st.number_input('Physicality', min_value = 0, max_value=100, value = 50)
56
+
57
+ #bikin submit button
58
+ submitted = st.form_submit_button('Predict')
59
+
60
+ #Inference
61
+ data_inf = {
62
+ 'Name' : name,
63
+ 'Age' : age,
64
+ 'Height' : height,
65
+ 'Weight' : weight,
66
+ 'Price' : price,
67
+ 'AttackingWorkRate' : attacking_work_rate,
68
+ 'DefensiveWorkRate' : devensive_work_rate,
69
+ 'PaceTotal' :pace_total,
70
+ 'ShootingTotal': shooting_total,
71
+ 'PassingTotal' : passing_total,
72
+ 'DribblingTotal' :dribbling_total,
73
+ 'DefendingTotal' :defending_total,
74
+ 'PhysicalityTotal':physicality,
75
+ }
76
+
77
+ data_inf = pd.DataFrame([data_inf])
78
+ st.dataframe(data_inf)
79
+
80
+ #Logic ketika predic button ditekan
81
+
82
+ if submitted:
83
+ #split between numerical and categorical columns
84
+ data_inf_num = data_inf[list_num_col]
85
+ data_inf_cat = data_inf[list_cat_col]
86
+
87
+ #Scaling & Encoding
88
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
89
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
90
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
91
+
92
+ #predict using linear reg model
93
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
94
+
95
+ st.write('## Rating : ', str(int(y_pred_inf)))
96
+
97
+ if __name__ == '__main__':
98
+ 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