Spaces:
Sleeping
Sleeping
Upload 10 files
Browse files- app.py +10 -0
- dada.jpg +0 -0
- eda.py +64 -0
- list_cat_cols.txt +1 -0
- list_num_cols.txt +1 -0
- model_encoder.pkl +3 -0
- model_lin_reg.pkl +3 -0
- model_scaler.pkl +3 -0
- prediction.py +95 -0
- requirements.txt +8 -0
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()
|
dada.jpg
ADDED
eda.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 judul
|
10 |
+
st.title('FIFA 2022 Player Rating Prediction')
|
11 |
+
|
12 |
+
#membuat sub header
|
13 |
+
st.subheader('EDA untuk Analisa Dataset FIFA 2022')
|
14 |
+
|
15 |
+
#tambahkan gambar
|
16 |
+
image = Image.open('dada.jpg')
|
17 |
+
st.image(image, caption = 'FIFA 2022')
|
18 |
+
|
19 |
+
#menambahkan deskripsi
|
20 |
+
st.write('Page ini dibuat oleh bagus')
|
21 |
+
|
22 |
+
#font size
|
23 |
+
#font terbesar
|
24 |
+
st.write('# Halo')
|
25 |
+
st.write('## Halo')
|
26 |
+
#bold
|
27 |
+
st.write('**Tes**')
|
28 |
+
#italic
|
29 |
+
st.write('*Tes*')
|
30 |
+
|
31 |
+
#mmebuat batas dengan garis lurus
|
32 |
+
st.markdown('---')
|
33 |
+
|
34 |
+
#show dataframe
|
35 |
+
data = pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
|
36 |
+
st.dataframe(data)
|
37 |
+
|
38 |
+
#membuat bar plot
|
39 |
+
st.write('#### Plot AttackingWorkRate')
|
40 |
+
fig = plt.figure(figsize=(15,5))
|
41 |
+
sns.countplot(x='AttackingWorkRate', data = data)
|
42 |
+
st.pyplot(fig)
|
43 |
+
|
44 |
+
#membuat histogram
|
45 |
+
st.write('#### Histogram of Rating')
|
46 |
+
fig = plt.figure(figsize=(15,5))
|
47 |
+
sns.histplot(data['Overall'], bins = 30, kde = True)
|
48 |
+
st.pyplot(fig)
|
49 |
+
|
50 |
+
#membuat histogram berdasarkan input user
|
51 |
+
st.write('#### Histogram berdasarkan input user')
|
52 |
+
option = st.selectbox('Pilih column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
|
53 |
+
fig = plt.figure(figsize=(15,5))
|
54 |
+
sns.histplot(data[option], bins = 30, kde = True)
|
55 |
+
st.pyplot(fig)
|
56 |
+
|
57 |
+
#membuat plotly plot
|
58 |
+
#membandingkan ratingpemain bola dengan proce nya
|
59 |
+
st.write('#### Plotly plot - ValueEUR vs Overall')
|
60 |
+
fig = px.scatter(data, x = 'ValueEUR', y = 'Overall', hover_data = ['Name', 'Age'])
|
61 |
+
st.plotly_chart(fig)
|
62 |
+
|
63 |
+
if __name__ == '__main__':
|
64 |
+
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:4329a128d619c1c5effa1b49e354bfb8f76f5f39ccfb9672fa1a687156d30f5c
|
3 |
+
size 578
|
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,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
#Load model
|
9 |
+
|
10 |
+
with open('list_cat_cols.txt', 'r') as file_1:
|
11 |
+
list_cat_col = json.load(file_1)
|
12 |
+
|
13 |
+
with open('list_num_cols.txt', 'r') as file_2:
|
14 |
+
list_num_col = json.load(file_2)
|
15 |
+
|
16 |
+
with open('model_encoder.pkl', 'rb') as file_3:
|
17 |
+
model_encoder = pickle.load(file_3)
|
18 |
+
|
19 |
+
with open('model_scaler.pkl', 'rb') as file_4:
|
20 |
+
model_scaler = pickle.load(file_4)
|
21 |
+
|
22 |
+
with open('model_lin_reg.pkl', 'rb') as file_5:
|
23 |
+
model_lin_reg = pickle.load(file_5)
|
24 |
+
|
25 |
+
def run():
|
26 |
+
with st.form('form_fifa_2022'):
|
27 |
+
#nama, value untuk default value
|
28 |
+
name = st.text_input('Name', value = ' ')
|
29 |
+
|
30 |
+
#age, min_value untuk minimum nilai yang bisa diisi, max_value maksimum nilai yang bisa diisi
|
31 |
+
age = st.number_input('Age', value = 25, min_value = 15, max_value = 60, help = 'isi dengan usia pemain')
|
32 |
+
|
33 |
+
#height
|
34 |
+
height = st.number_input('Height', value = 170, min_value = 100, help = 'in cm')
|
35 |
+
|
36 |
+
weight = st.slider('Weight', value = 70, min_value = 50, max_value = 150)
|
37 |
+
|
38 |
+
price = st.number_input('Price', value = 0)
|
39 |
+
|
40 |
+
st.markdown('---')
|
41 |
+
#index untuk default value di selctbox/radio button
|
42 |
+
attacking_work_rate = st.selectbox('Attacking Work Rate', ('Low', 'Medium', 'High'), index = 1)
|
43 |
+
|
44 |
+
defensive_work_rate = st.radio('Defensive Work Rate', ('Low', 'Medium', 'High'), index = 1)
|
45 |
+
|
46 |
+
pace = st.number_input('Pace', min_value = 0, max_value = 100, value = 50)
|
47 |
+
shooting = st.number_input('Shooting Score', min_value = 0, max_value = 100, value = 50)
|
48 |
+
passing = st.number_input('Passing Score', min_value = 0, max_value = 100, value = 50)
|
49 |
+
dribbling = st.number_input('Dribbling Score', min_value = 0, max_value = 100, value = 50)
|
50 |
+
defending = st.number_input('Defending Score', min_value = 0, max_value = 100, value = 50)
|
51 |
+
physicality = st.number_input('Pysicality Score', min_value = 0, max_value = 100, value = 50)
|
52 |
+
|
53 |
+
#bikin submit button form
|
54 |
+
submitted = st.form_submit_button('Predict')
|
55 |
+
|
56 |
+
data_inf = {
|
57 |
+
'Name' : name,
|
58 |
+
'Age' : age,
|
59 |
+
'Height' : height,
|
60 |
+
'Weight' : weight,
|
61 |
+
'Price' : price,
|
62 |
+
'AttackingWorkRate' : attacking_work_rate,
|
63 |
+
'DefensiveWorkRate' : defensive_work_rate,
|
64 |
+
'PaceTotal' : pace,
|
65 |
+
'ShootingTotal' : shooting,
|
66 |
+
'PassingTotal' : passing,
|
67 |
+
'DribblingTotal' : dribbling,
|
68 |
+
'DefendingTotal' : defending,
|
69 |
+
'PhysicalityTotal' : physicality
|
70 |
+
}
|
71 |
+
data_inf = pd.DataFrame([data_inf])
|
72 |
+
st.dataframe(data_inf)
|
73 |
+
|
74 |
+
if submitted:
|
75 |
+
#split between numerical and categorical columns
|
76 |
+
data_inf_num = data_inf[list_num_col]
|
77 |
+
data_inf_cat = data_inf[list_cat_col]
|
78 |
+
|
79 |
+
#feature scaling and encoding
|
80 |
+
|
81 |
+
data_inf_num_scaled = model_scaler.transform(data_inf_num)
|
82 |
+
data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
|
83 |
+
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
|
84 |
+
|
85 |
+
#predict using linear reg model
|
86 |
+
|
87 |
+
y_pred_inf = model_lin_reg.predict(data_inf_final)
|
88 |
+
|
89 |
+
st.write('## Rating : ', str(int(y_pred_inf)))
|
90 |
+
|
91 |
+
|
92 |
+
if __name__ == '__main__':
|
93 |
+
run()
|
94 |
+
|
95 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
seaborn
|
4 |
+
matplotlib
|
5 |
+
numpy
|
6 |
+
scikit-learn==1.2.2
|
7 |
+
Pillow
|
8 |
+
plotly
|