Spaces:
Sleeping
Sleeping
Commit
·
206bf0d
1
Parent(s):
b145dc4
first commit
Browse files- app.py +9 -0
- bola.jpg +0 -0
- eda.py +59 -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 +102 -0
- requirements.txt +8 -0
app.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import eda
|
3 |
+
import prediction
|
4 |
+
|
5 |
+
page = st.sidebar.selectbox('Pilih Halaman :', ('EDA', 'Prediction'))
|
6 |
+
if page == 'EDA':
|
7 |
+
eda.run()
|
8 |
+
else:
|
9 |
+
prediction.run()
|
bola.jpg
ADDED
![]() |
eda.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# membaut title
|
10 |
+
st.title('Fifta 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 Hammam')
|
21 |
+
|
22 |
+
# Membuat markdown
|
23 |
+
st.markdown('---------')
|
24 |
+
|
25 |
+
# Show dataframe
|
26 |
+
df=pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
|
27 |
+
st.dataframe(df)
|
28 |
+
|
29 |
+
# Membuat bar plot
|
30 |
+
|
31 |
+
st.write('#### Plot AttackingWorkRate')
|
32 |
+
fig = plt.figure(figsize=(15,5))
|
33 |
+
sns.countplot(x='AttackingWorkRate', data=df)
|
34 |
+
st.pyplot(fig)
|
35 |
+
|
36 |
+
|
37 |
+
# Membuat histogram
|
38 |
+
|
39 |
+
st.write('#### Histogram of Rating')
|
40 |
+
fig = plt.figure(figsize=(15,5))
|
41 |
+
sns.histplot(df['Overall'], bins = 30, kde = True)
|
42 |
+
st.pyplot(fig)
|
43 |
+
|
44 |
+
# Membuat histogram berdasarkan inputan user
|
45 |
+
|
46 |
+
st.write('#### histogram berdasarkan input user')
|
47 |
+
option = st.selectbox('pilih column :', ('Age', 'Weight', 'Height', 'ShootingTotal'))
|
48 |
+
fig = plt.figure(figsize=(15,5))
|
49 |
+
sns.histplot(df[option], bins=30, kde=True)
|
50 |
+
st.pyplot(fig)
|
51 |
+
|
52 |
+
# Membuat plotly plot
|
53 |
+
|
54 |
+
st.write('#### plotly plot - ValueEUR vs Overall')
|
55 |
+
fig = px.scatter(df, x = 'ValueEUR', y = 'Overall', hover_data=['Name', 'Age'])
|
56 |
+
st.plotly_chart(fig)
|
57 |
+
|
58 |
+
if __name__ == '__main__':
|
59 |
+
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,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import json
|
6 |
+
import sklearn
|
7 |
+
|
8 |
+
def run():
|
9 |
+
with st.form('form-fifa_2022'):
|
10 |
+
#field nama
|
11 |
+
name = st.text_input('Name', value='')
|
12 |
+
|
13 |
+
#field umur
|
14 |
+
age = st.number_input('Age', min_value=16, max_value=60, value = 25, step=1, help='Usia pemain')
|
15 |
+
|
16 |
+
#field tinggi badan
|
17 |
+
height = st.slider('Height', 100, 250, 170)
|
18 |
+
|
19 |
+
#field weight
|
20 |
+
weight = st.number_input('Weight', 50, 150, 70)
|
21 |
+
|
22 |
+
#field price
|
23 |
+
price = st.number_input('Price', value=0)
|
24 |
+
|
25 |
+
st.markdown('-----')
|
26 |
+
|
27 |
+
#field attacking work rate
|
28 |
+
attacking_work_rate = st.selectbox('Attacking Work Rate', ('Low', 'Medium', 'High'), index=1)
|
29 |
+
|
30 |
+
#field defensive work rate
|
31 |
+
defensive_work_rate = st.selectbox('Defensive Work Rate', ('Low', 'Medium', 'High'), index=1)
|
32 |
+
|
33 |
+
#field pace total
|
34 |
+
pace_total = st.number_input('Pace', min_value=0, max_value=100, value=50)
|
35 |
+
#field shooting total
|
36 |
+
shooting_total = st.number_input('Shooting', min_value=0, max_value=100, value=50)
|
37 |
+
#filed passing total
|
38 |
+
passing_total = st.number_input('Passing', min_value=0, max_value=100, value=50)
|
39 |
+
#field dribbling total
|
40 |
+
dribbling_total = st.number_input('Dribbling', min_value=0, max_value=100, value=50)
|
41 |
+
#filed defending total
|
42 |
+
defending_total = st.number_input('Defending', min_value=0, max_value=100, value=50)
|
43 |
+
#field physicality
|
44 |
+
physicality = st.number_input('Physicality', min_value=0, max_value=100, value=50)
|
45 |
+
|
46 |
+
#bikin submit button
|
47 |
+
submitted = st.form_submit_button('Predict')
|
48 |
+
|
49 |
+
|
50 |
+
#inference
|
51 |
+
#load all files
|
52 |
+
|
53 |
+
with open('list_cat_cols.txt', 'r') as file_1:
|
54 |
+
list_cat_cols = json.load(file_1)
|
55 |
+
with open('list_num_cols.txt', 'r') as file_2:
|
56 |
+
list_num_cols = json.load(file_2)
|
57 |
+
with open('model_scaler.pkl', 'rb') as file_3:
|
58 |
+
model_scaler = pickle.load(file_3)
|
59 |
+
with open('model_encoder.pkl', 'rb') as file_4:
|
60 |
+
model_encoder = pickle.load(file_4)
|
61 |
+
with open('model_lin_reg.pkl', 'rb') as file_5:
|
62 |
+
model_lin_reg = pickle.load(file_5)
|
63 |
+
data_inf = {
|
64 |
+
'Name' : name,
|
65 |
+
'Age' : age,
|
66 |
+
'Height' : height,
|
67 |
+
'Weight' : weight,
|
68 |
+
'Price' : price,
|
69 |
+
'AttackingWorkRate' : attacking_work_rate,
|
70 |
+
'DefensiveWorkRate' : defensive_work_rate,
|
71 |
+
'PaceTotal' :pace_total,
|
72 |
+
'ShootingTotal': shooting_total,
|
73 |
+
'PassingTotal' : passing_total,
|
74 |
+
'DribblingTotal': dribbling_total,
|
75 |
+
'DefendingTotal' :defending_total,
|
76 |
+
'PhysicalityTotal':physicality,
|
77 |
+
}
|
78 |
+
|
79 |
+
|
80 |
+
data_inf = pd.DataFrame([data_inf])
|
81 |
+
st.dataframe(data_inf)
|
82 |
+
|
83 |
+
#logic ketika predic button ditekan
|
84 |
+
|
85 |
+
if submitted:
|
86 |
+
#split between numerical and categorical collumn
|
87 |
+
data_inf_num = data_inf[list_num_cols]
|
88 |
+
data_inf_cat = data_inf[list_cat_cols]
|
89 |
+
|
90 |
+
|
91 |
+
#scalling dan encoding
|
92 |
+
data_inf_num_scaled = model_scaler.transform(data_inf_num)
|
93 |
+
data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
|
94 |
+
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
|
95 |
+
|
96 |
+
#preedict using linear reg model
|
97 |
+
y_pred_inf = model_lin_reg.predict(data_inf_final)
|
98 |
+
|
99 |
+
st.write('## Rating :', str(int(y_pred_inf)))
|
100 |
+
|
101 |
+
if __name__ == '__main__':
|
102 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
matplotlib
|
5 |
+
seaborn
|
6 |
+
plotly
|
7 |
+
Pillow
|
8 |
+
scikit-learn==1.2.2
|