Spaces:
Sleeping
Sleeping
danupurnomo
commited on
Commit
•
f8dca17
1
Parent(s):
66f9905
Upload 2 files
Browse files- eda.py +60 -0
- prediction.py +80 -0
eda.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
st.set_page_config(
|
9 |
+
page_title='FIFA 2022',
|
10 |
+
layout='wide',
|
11 |
+
initial_sidebar_state='expanded'
|
12 |
+
)
|
13 |
+
|
14 |
+
def run():
|
15 |
+
# Membuat Title
|
16 |
+
st.title('FIFA 2022 Player Rating Prediction - Danu Purnomo')
|
17 |
+
|
18 |
+
# Membuat Sub Header
|
19 |
+
st.subheader('EDA untuk Analisa Dataset FIFA 2022')
|
20 |
+
|
21 |
+
# Menambahkan Gambar
|
22 |
+
image = Image.open('soccer.jpg')
|
23 |
+
st.image(image, caption='FIFA 2022')
|
24 |
+
|
25 |
+
# Menambahkan Deskripsi
|
26 |
+
st.write('Page ini dibuat oleh *Danu Purnomo*')
|
27 |
+
st.write('# Halo')
|
28 |
+
st.write('## Halo')
|
29 |
+
st.write('### Halo')
|
30 |
+
|
31 |
+
# Show DataFrame
|
32 |
+
data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
|
33 |
+
st.dataframe(data)
|
34 |
+
|
35 |
+
# Membuat Barplot
|
36 |
+
st.write('#### Plot AttackingWorkRate')
|
37 |
+
fig = plt.figure(figsize=(15,5))
|
38 |
+
sns.countplot(x='AttackingWorkRate', data=data)
|
39 |
+
st.pyplot(fig)
|
40 |
+
|
41 |
+
# Membuat Histogram
|
42 |
+
st.write('#### Histogram of Rating')
|
43 |
+
fig = plt.figure(figsize=(15, 5))
|
44 |
+
sns.histplot(data['Overall'], bins=30, kde=True)
|
45 |
+
st.pyplot(fig)
|
46 |
+
|
47 |
+
# Membuat Histogram Berdasarkan Input User
|
48 |
+
st.write('#### Histogram berdasarkan input user')
|
49 |
+
pilihan = st.radio('Pilih column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
|
50 |
+
fig = plt.figure(figsize=(15, 5))
|
51 |
+
sns.histplot(data[pilihan], bins=30, kde=True)
|
52 |
+
st.pyplot(fig)
|
53 |
+
|
54 |
+
# Membuat Plotly Plot
|
55 |
+
st.write('#### Plotly Plot - ValueEUR dengan Overall')
|
56 |
+
fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Weight'])
|
57 |
+
st.plotly_chart(fig)
|
58 |
+
|
59 |
+
if __name__ == '__main__':
|
60 |
+
run()
|
prediction.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import json
|
5 |
+
import pickle
|
6 |
+
|
7 |
+
# Load All Files
|
8 |
+
|
9 |
+
with open('model_lin_reg.pkl', 'rb') as file_1:
|
10 |
+
model_lin_reg = pickle.load(file_1)
|
11 |
+
|
12 |
+
with open('model_scaler.pkl', 'rb') as file_2:
|
13 |
+
model_scaler = pickle.load(file_2)
|
14 |
+
|
15 |
+
with open('model_encoder.pkl','rb') as file_3:
|
16 |
+
model_encoder = pickle.load(file_3)
|
17 |
+
|
18 |
+
with open('list_num_cols.txt', 'r') as file_4:
|
19 |
+
list_num_cols = json.load(file_4)
|
20 |
+
|
21 |
+
with open('list_cat_cols.txt', 'r') as file_5:
|
22 |
+
list_cat_cols = json.load(file_5)
|
23 |
+
|
24 |
+
def run():
|
25 |
+
# Membuat Form
|
26 |
+
with st.form(key='form_fifa_2022'):
|
27 |
+
name = st.text_input('Full Name', value='')
|
28 |
+
age = st.number_input('Age', min_value=16, max_value=60, value=25, step=1, help='Usia pemain')
|
29 |
+
weight = st.number_input('Weight', min_value=50, max_value=150, value=70)
|
30 |
+
height = st.slider('Height', 100, 250, 170)
|
31 |
+
price = st.number_input('Price', min_value=0, max_value=1000000000, value=0)
|
32 |
+
st.markdown('---')
|
33 |
+
|
34 |
+
attacking_work_rate = st.selectbox('AttackingWorkRate', ('Low', 'Medium', 'High'), index=1)
|
35 |
+
defensive_work_rate = st.selectbox('DefensiveWorkrate', ('Low', 'Medium', 'High'), index=0)
|
36 |
+
st.markdown('---')
|
37 |
+
|
38 |
+
pace = st.number_input('Pace', min_value=0, max_value=100, value=50)
|
39 |
+
shooting = st.number_input('Shooting', min_value=0, max_value=100, value=50)
|
40 |
+
passing = st.number_input('Passing', min_value=0, max_value=100, value=50)
|
41 |
+
dribbling = st.number_input('Dribbling', min_value=0, max_value=100, value=50)
|
42 |
+
defending = st.number_input('Defending', min_value=0, max_value=100, value=50)
|
43 |
+
physicality = st.number_input('Physicality', min_value=0, max_value=100, value=50)
|
44 |
+
|
45 |
+
submitted = st.form_submit_button('Predict')
|
46 |
+
|
47 |
+
data_inf = {
|
48 |
+
'Name': name,
|
49 |
+
'Age': age,
|
50 |
+
'Height': height,
|
51 |
+
'Weight': weight,
|
52 |
+
'Price': price,
|
53 |
+
'AttackingWorkRate': attacking_work_rate,
|
54 |
+
'DefensiveWorkRate': defensive_work_rate,
|
55 |
+
'PaceTotal': pace,
|
56 |
+
'ShootingTotal': shooting,
|
57 |
+
'PassingTotal': passing,
|
58 |
+
'DribblingTotal': dribbling,
|
59 |
+
'DefendingTotal': defending,
|
60 |
+
'PhysicalityTotal': physicality
|
61 |
+
}
|
62 |
+
data_inf = pd.DataFrame([data_inf])
|
63 |
+
st.dataframe(data_inf)
|
64 |
+
|
65 |
+
if submitted:
|
66 |
+
# Split between Numerical Columns and Categorical Columns
|
67 |
+
data_inf_num = data_inf[list_num_cols]
|
68 |
+
data_inf_cat = data_inf[list_cat_cols]
|
69 |
+
|
70 |
+
# Feature Scaling and Feature Encoding
|
71 |
+
data_inf_num_scaled = model_scaler.transform(data_inf_num)
|
72 |
+
data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
|
73 |
+
data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
|
74 |
+
|
75 |
+
# Predict using Linear Regression
|
76 |
+
y_pred_inf = model_lin_reg.predict(data_inf_final)
|
77 |
+
st.write('# Rating : ', str(int(y_pred_inf)))
|
78 |
+
|
79 |
+
if __name__ == '__main__':
|
80 |
+
run()
|