ahmadluay commited on
Commit
fa71090
1 Parent(s): 4106336
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
+ 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')
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')
27
+ st.write('# Halo')
28
+
29
+
30
+ # show dataframe
31
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
32
+ st.dataframe(data)
33
+
34
+ # membuat barplot
35
+ st.write('#### Plot AttackingWorkRate')
36
+ fig =plt.figure(figsize=(15,5))
37
+ sns.countplot(x='AttackingWorkRate',data=data)
38
+ st.pyplot(fig)
39
+
40
+ # Membuat histogram
41
+ st.write('### Histogram of Rating')
42
+ fig = plt.figure(figsize=(15,5))
43
+ sns.histplot(data['Overall'],bins=30,kde=True)
44
+ st.pyplot(fig)
45
+
46
+ # Membuat Plotly Plot
47
+ st.write('#### PlotlyPlots - ValueEUR dengan Overall')
48
+ fig = px.scatter(data, x='ValueEUR', y='Overall',hover_data=['Name','Age'])
49
+ st.plotly_chart(fig)
50
+
51
+ # Membuat histogram berdasarkan input user
52
+ st.write('### Histogram berdasarkan input user')
53
+ pilihan = st.selectbox('Pilih column :',('Age','Weight','Height','ShootingTotal'))
54
+ fig = plt.figure(figsize=(15,5))
55
+ sns.histplot(data[pilihan],bins=30,kde=True)
56
+ st.pyplot(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"]
main.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda # python file
3
+ import prediction # python file
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()
11
+
model_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d679ce958dcc5fde5d08221484e8d07eeb6a0acb2298a30087aa791acc886bf7
3
+ size 572
model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce6fbcfd793f11352525ffe462688212f5d081f879efd4dd1ccbf8f990336cf9
3
+ size 595
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e1f92e11e77b25cb4695aa80cadd3867d32115656e74a2c1b4417080e138841
3
+ size 1096
prediction.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import json
6
+ # Load All Files
7
+
8
+ with open('model_lin_reg.pkl', 'rb') as file_1:
9
+ model_lin_reg = pickle.load(file_1)
10
+
11
+ with open('model_scaler.pkl', 'rb') as file_2:
12
+ model_scaler = pickle.load(file_2)
13
+
14
+ with open('model_encoder.pkl','rb') as file_3:
15
+ model_encoder = pickle.load(file_3)
16
+
17
+ with open('list_num_cols.txt', 'r') as file_4:
18
+ list_num_cols = json.load(file_4)
19
+
20
+ with open('list_cat_cols.txt', 'r') as file_5:
21
+ list_cat_cols = json.load(file_5)
22
+
23
+ def run():
24
+ with st.form(key='form_fifa_2022'):
25
+ name = st.text_input('Name',value='')
26
+ age = st.number_input('Age',min_value=16,max_value=60,value=25,step=1,help='Usia Pemain')
27
+ weight = st.number_input('Weight',min_value=50, max_value=150,value=70)
28
+ height = st.slider('Height',50,250,170)
29
+ price = st.number_input('Price',min_value=0,max_value=1000000000,value=0)
30
+ st.markdown ('---')
31
+
32
+ attacking_work_rate = st.selectbox('AttackingWorkRate',('Low','Medium','High'),index=1)
33
+ defensive_work_rate = st.radio('DefensiveWorkRate',('Low','Medium','High'),index=1)
34
+
35
+ st.markdown ('---')
36
+
37
+ pace = st.number_input('Pace',min_value=0,max_value=100,value=50)
38
+ shooting = st.number_input('Shooting',min_value=0,max_value=100,value=50)
39
+ passing = st.number_input('Passing',min_value=0,max_value=100,value=50)
40
+ dribbling = st.number_input('Dribbling',min_value=0,max_value=100,value=50)
41
+ defending = st.number_input('Defending',min_value=0,max_value=100,value=50)
42
+ physicality = st.number_input('Physicality',min_value=0,max_value=100,value=50)
43
+
44
+ submitted = st.form_submit_button('predict')
45
+
46
+ data_inf = {
47
+ 'Name': name,
48
+ 'Age': age,
49
+ 'Height': height,
50
+ 'Weight': weight,
51
+ 'Price': price,
52
+ 'AttackingWorkRate': attacking_work_rate,
53
+ 'DefensiveWorkRate': defensive_work_rate,
54
+ 'PaceTotal': pace,
55
+ 'ShootingTotal': shooting,
56
+ 'PassingTotal': passing,
57
+ 'DribblingTotal': dribbling,
58
+ 'DefendingTotal': defending,
59
+ 'PhysicalityTotal':physicality
60
+ }
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
+
68
+ data_inf_num = data_inf[list_num_cols]
69
+ data_inf_cat = data_inf[list_cat_cols]
70
+
71
+ # Feature Scaling and Feature Encoding
72
+
73
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
74
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
75
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
76
+
77
+ # Predict using Linear Regression
78
+
79
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
80
+ st.write('# Rating: ',str(int(y_pred_inf)))
81
+
82
+ if __name__ == '__main__':
83
+ run()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ numpy
6
+ scikit-learn==1.2.1