FerdiErs commited on
Commit
19720a9
·
1 Parent(s): 8ddaf4d

'firstcommit'

Browse files
Files changed (8) hide show
  1. EDA.py +68 -0
  2. list_cat_cols.txt +1 -0
  3. list_num_cols.txt +1 -0
  4. main.py +10 -0
  5. model_encoder.pkl +3 -0
  6. model_lin_reg.pkl +3 -0
  7. model_scaler.pkl +3 -0
  8. prediction.py +84 -0
EDA.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 20222 EDA',
10
+ layout = 'wide',
11
+ initial_sidebar_state='expanded'
12
+ )
13
+
14
+ def run():
15
+
16
+ # Membuat Title
17
+ st.title('FIFA 2022 Player Rating Prediction')
18
+
19
+ # Membuat Sub- Header
20
+ st.subheader('EDA untuk analisa Dataset FIFA 2022')
21
+
22
+ # Insert Gambar
23
+ image = Image.open('D:\Hacktiv8\Batch_020_RMT\Soccer.jpg')
24
+ st.image(image, caption='FIFA 2022')
25
+
26
+ # Menambahkan Deskripsi
27
+ st.write('Page ini dibuat oleh *Ferdiansyah Ersatiyo*')
28
+ st.write('# Halo') # seperti markdown pada google colab
29
+
30
+ # Membuat garis lurus
31
+ st.markdown('---')
32
+
33
+ # Magic Syntax
34
+ '''
35
+ Pada page kali ini, Penulis akan melakukan eksplorasi sederhana
36
+ Dataset yang digunakan adalah dataset FIFA 2022.
37
+ Dataset ini berasal dari web sofifa.com
38
+ '''
39
+
40
+ # show dataframe
41
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
42
+ st.dataframe(data)
43
+
44
+ # Membuat Barplot
45
+ st.write('### Plot AttackingWorkRate')
46
+ fig = plt.figure(figsize=(15,5))
47
+ sns.countplot(x='AttackingWorkRate', data=data)
48
+ st.pyplot(fig)
49
+
50
+ # Membuat Histogram
51
+ st.write('### Histogram of Rating')
52
+ fig = plt.figure(figsize=(15,5))
53
+ sns.histplot(data['Overall'], bins= 30, kde=True)
54
+ st.pyplot(fig)
55
+
56
+ # Membuat Histogram berdasarkan input user
57
+ st.write('### Histogram berdasarkan input user')
58
+ pilihan = st.selectbox('pilih column : ',['Age','Weight','Height', 'ShootingTotal'])
59
+ fig = plt.figure(figsize=(15,5))
60
+ sns.histplot(data[pilihan], bins= 30, kde=True)
61
+ st.pyplot(fig)
62
+ # Membuat Plotly Plot
63
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
64
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Age'])
65
+ st.plotly_chart(fig)
66
+
67
+ if __name__== '__main__':
68
+ 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,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()
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,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
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
+
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', 150,250,170)
31
+ price = st.number_input ('price',min_value=0, max_value=10000000000, value= 0)
32
+ st.markdown('---')
33
+
34
+ attacking_work_rate = st.radio('Attacking Work Rate', ('Low', 'Medium', 'High'), index = 1)
35
+ defensive_work_rate = st.selectbox('Defensive Work Rate', ('Low', 'Medium', 'High'), index = 1)
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
+
46
+ submitted = st.form_submit_button('Predict')
47
+
48
+
49
+ data_inf = {
50
+ 'Name': name,
51
+ 'Age': age,
52
+ 'Height': Height,
53
+ 'Weight': Weight,
54
+ 'Price': price,
55
+ 'AttackingWorkRate': attacking_work_rate,
56
+ 'DefensiveWorkRate': defensive_work_rate,
57
+ 'PaceTotal': pace,
58
+ 'ShootingTotal': shooting,
59
+ 'PassingTotal': passing,
60
+ 'DribblingTotal': Dribbling,
61
+ 'DefendingTotal': defending,
62
+ 'PhysicalityTotal': physicality
63
+ }
64
+
65
+ data_inf = pd.DataFrame([data_inf])
66
+ st.dataframe(data_inf)
67
+
68
+ if submitted:
69
+ # Split between Numerical Columns and Categorical Columns
70
+ data_inf_num = data_inf[list_num_cols]
71
+ data_inf_cat = data_inf[list_cat_cols]
72
+
73
+ # Feature Scaling and Feature Encoding
74
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
75
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
76
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
77
+
78
+ # Predict using Linear Regression
79
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
80
+
81
+ st.write('# Rating : ', str(int(y_pred_inf)))
82
+
83
+ if __name__== '__main__':
84
+ run()