Upload 10 files
Browse files- app.py +10 -0
- eda.py +76 -0
- gambar1.png +0 -0
- list_cat_columns.txt +1 -0
- list_num_columns.txt +1 -0
- model_encoder.pkl +3 -0
- model_lin_reg.pkl +3 -0
- model_scaler.pkl +3 -0
- prediction.py +78 -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 |
+
navigation = st.sidebar.selectbox('Pilih Halaman: ', ('EDA', 'Predict a Player'))
|
6 |
+
|
7 |
+
if navigation == 'EDA':
|
8 |
+
eda.run()
|
9 |
+
else:
|
10 |
+
prediction.run()
|
eda.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Tittle
|
10 |
+
st.title('FIFA 2022 Player Rating Prediction')
|
11 |
+
|
12 |
+
# membuat sub header
|
13 |
+
st.subheader('Eda untuk Analisis Dataset FIFA 2022')
|
14 |
+
|
15 |
+
|
16 |
+
# menambahkan gambar
|
17 |
+
st.image('https://cdn.pixabay.com/photo/2016/06/22/08/40/cow-1472655_1280.png', caption='SAPI')
|
18 |
+
|
19 |
+
st.image('gambar1.png')
|
20 |
+
|
21 |
+
# menambahkan deskripsi
|
22 |
+
st.write('Page ini dibuat oleh Kumala Chann') #anggap seperti markdown
|
23 |
+
st.write('# Halo')
|
24 |
+
st.write('## Halo')
|
25 |
+
st.write('### Halo')
|
26 |
+
|
27 |
+
# membuat garis lurus
|
28 |
+
st.markdown('---')
|
29 |
+
|
30 |
+
# MAGIC syntax
|
31 |
+
'''
|
32 |
+
Pada page kali ini penulis akan melakukan eksplorasi sederhana,
|
33 |
+
dataset yang digunakan adalah dataset FIFA 2022.
|
34 |
+
Dataset ini berasal dari web sofifa.com
|
35 |
+
'''
|
36 |
+
|
37 |
+
df = pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
|
38 |
+
st.dataframe(df)
|
39 |
+
|
40 |
+
# membuat barplot
|
41 |
+
st.write('### Plot AttackingWorkRate')
|
42 |
+
fig = plt.figure(figsize=(15,5))
|
43 |
+
sns.countplot(x='AttackingWorkRate', data=df)
|
44 |
+
st.pyplot(fig)
|
45 |
+
st.write('Ini analisisnya')
|
46 |
+
|
47 |
+
# membuat histogram
|
48 |
+
st.write('### Histogram Berdasarkan Overall')
|
49 |
+
fig = plt.figure(figsize=(15,5))
|
50 |
+
sns.histplot(df['Overall'], bins=30, kde=True)
|
51 |
+
st.pyplot(fig)
|
52 |
+
|
53 |
+
# membuat histogram berdasrakan input user
|
54 |
+
st.write('### Histogram Berdasarkan Input User')
|
55 |
+
pilihan = st.selectbox('Pilih kolom: ', ('Age','Weight','Height','ShootingTotal'))
|
56 |
+
fig = plt.figure(figsize=(15,5))
|
57 |
+
sns.histplot(df[pilihan], bins=30, kde=True)
|
58 |
+
st.pyplot(fig)
|
59 |
+
|
60 |
+
if pilihan == 'Height':
|
61 |
+
st.write('Kolom height sangat skew')
|
62 |
+
elif pilihan == 'Weight':
|
63 |
+
st.write('Kolom weight sangat skew')
|
64 |
+
elif pilihan == 'Age':
|
65 |
+
st.write('Kolom age sangat skew')
|
66 |
+
else:
|
67 |
+
st.write('Kolom shooting total sangat skew')
|
68 |
+
|
69 |
+
# interactif chart
|
70 |
+
st.write('### Plotly Plot - ValueEUR dengan Overall')
|
71 |
+
fig = px.scatter(df, x='ValueEUR', y='Overall',hover_data=['Name','Age'])
|
72 |
+
st.plotly_chart(fig)
|
73 |
+
|
74 |
+
|
75 |
+
if __name__ == '__main__':
|
76 |
+
run()
|
gambar1.png
ADDED
list_cat_columns.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
["AttackRate", "DefenseRate"]
|
list_num_columns.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:1ddd248a5fdd882efccbbc8915d77c9e9812927e46bc602d2d31f34a0394384d
|
3 |
+
size 629
|
model_lin_reg.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a500c8ffbd62182601c3cfd2cab7a037a15498e6ee017ce469537536e4db3bf7
|
3 |
+
size 601
|
model_scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d53ae4a0f5d781eeda4c537f90ef117899a38cc7856ed24cd2946b6fc243f976
|
3 |
+
size 1102
|
prediction.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
import json
|
6 |
+
|
7 |
+
# Load datanya
|
8 |
+
with open('list_num_columns.txt', 'r') as file_1:
|
9 |
+
list_num_cols = json.load(file_1)
|
10 |
+
|
11 |
+
with open('list_cat_columns.txt', 'r') as file_2:
|
12 |
+
list_cat_cols = json.load(file_2)
|
13 |
+
|
14 |
+
with open('model_scaler.pkl', 'rb') as file_3:
|
15 |
+
model_scaler = pickle.load(file_3)
|
16 |
+
|
17 |
+
with open('model_encoder.pkl', 'rb') as file_4:
|
18 |
+
model_encoder = pickle.load(file_4)
|
19 |
+
|
20 |
+
with open('model_lin_reg.pkl', 'rb') as file_5:
|
21 |
+
model_lin_reg = pickle.load(file_5)
|
22 |
+
|
23 |
+
def run():
|
24 |
+
with st.form(key='Form Parameter'):
|
25 |
+
name = st.text_input('Name', value='')
|
26 |
+
age = st.number_input('Age', min_value=0, max_value=70, step=1)
|
27 |
+
weight = st.number_input('Weight', min_value=0, max_value=150, step=1)
|
28 |
+
height = st.slider('Height', 150, 225, 165)
|
29 |
+
price = st.number_input('Price', min_value=0, max_value=1000000000, step=1000)
|
30 |
+
st.markdown('---')
|
31 |
+
AttackingWorkRate = st.selectbox('Attacking Work Rate', ('Low','Medium','High'),index=0)
|
32 |
+
DefensiveWorkRate = st.selectbox('Defensive Work Rate', ('Low','Medium','High'),index=1)
|
33 |
+
st.markdown('---')
|
34 |
+
pace = st.number_input('Pace', min_value=0, max_value=100, step=1)
|
35 |
+
shooting = st.number_input('Shooting Total', min_value=0, max_value=100, step=1)
|
36 |
+
passing = st.number_input('Passing', min_value=0, max_value=100, step=1)
|
37 |
+
dribbling = st.number_input('Dribbling', min_value=0, max_value=100, step=1)
|
38 |
+
defending = st.number_input('Defending', min_value=0, max_value=100, step=1)
|
39 |
+
physicality = st.number_input('Physicality', min_value=0, max_value=100, step=1)
|
40 |
+
|
41 |
+
submitted = st.form_submit_button('Predict')
|
42 |
+
|
43 |
+
data_inf = {'Name': name,
|
44 |
+
'Age': age,
|
45 |
+
'Height': height,
|
46 |
+
'Weight': weight,
|
47 |
+
'Price': price,
|
48 |
+
'AttackRate':AttackingWorkRate,
|
49 |
+
'DefenseRate': DefensiveWorkRate,
|
50 |
+
'PaceTotal': pace,
|
51 |
+
'ShootingTotal':shooting,
|
52 |
+
'PassingTotal':passing ,
|
53 |
+
'DribblingTotal':dribbling,
|
54 |
+
'DefendingTotal': defending,
|
55 |
+
'PhysicalityTotal': physicality}
|
56 |
+
|
57 |
+
df = pd.DataFrame([data_inf])
|
58 |
+
st.dataframe(df)
|
59 |
+
|
60 |
+
|
61 |
+
if submitted:
|
62 |
+
# split antara num and cat column
|
63 |
+
data_inf_num = df[list_num_cols]
|
64 |
+
data_inf_cat = df[list_cat_cols]
|
65 |
+
|
66 |
+
# scaling and encoding
|
67 |
+
data_inf_num_scaled = model_scaler.transform(data_inf_num)
|
68 |
+
data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
|
69 |
+
|
70 |
+
# merge
|
71 |
+
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
|
72 |
+
|
73 |
+
# predict
|
74 |
+
y_pred_inf = model_lin_reg.predict(data_inf_final)
|
75 |
+
st.write('# Rating: ',str(np.round(y_pred_inf))[1:3])
|
76 |
+
|
77 |
+
if __name__ == '__main__':
|
78 |
+
run()
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit == 1.31.1
|
2 |
+
pandas == 2.2.1
|
3 |
+
numpy == 1.26.4
|
4 |
+
seaborn == 0.13.2
|
5 |
+
matplotlib == 3.8.3
|
6 |
+
scikit-learn == 1.4.1.post1
|
7 |
+
plotly == 5.19.0
|
8 |
+
Pillow ==
|