Kurkur99 commited on
Commit
0e98454
·
1 Parent(s): 50e2b0c
eda.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Menambahkan Gambar
21
+ image = Image.open('gambar.jpg')
22
+ st.image(image, caption='FIFA 2022')
23
+
24
+ # Menambahkan Deskripsi
25
+ st.write('Page ini dibuat oleh Theo Nugraha')
26
+ st.write('# Teks 1')
27
+ st.write('## Teks 2')
28
+ st.write('### Teks 3')
29
+
30
+ # Membuat Garis Lurus
31
+ st.markdown('---')
32
+
33
+ # Show Data Frame
34
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
35
+ st.dataframe(data)
36
+
37
+ # Membuat Bar Plot
38
+ st.write('#### Plot AttackingWorkRate')
39
+ fig = plt.figure(figsize=(15, 5))
40
+ sns.countplot(x='AttackingWorkRate', data=data)
41
+ st.pyplot(fig)
42
+
43
+ # Membuat Histogram
44
+ st.write('#### Histogram of Rating')
45
+ fig = plt.figure(figsize=(15, 5))
46
+ sns.histplot(data['Overall'], bins=30, kde=True)
47
+ st.pyplot(fig)
48
+
49
+ # Membuat Histogram Berdasarkan Input User
50
+ st.write('#### Histogram Berdasarkan Input User')
51
+ pilihan = st.selectbox('Pilih Column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
52
+ fig = plt.figure(figsize=(15, 5))
53
+ sns.histplot(data[pilihan], bins=30, kde=True)
54
+ st.pyplot(fig)
55
+
56
+ # Membuat Plotly Plot
57
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
58
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Age'])
59
+ st.plotly_chart(fig)
60
+
61
+ if __name__ == '__main__':
62
+ 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
3
+ import prediction
4
+
5
+
6
+ page = st.sidebar.selectbox ('Pilih Halaman : ', ('eda', 'predict A player'))
7
+
8
+ if page == 'eda':
9
+ eda.run ()
10
+ else:
11
+ 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,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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('list_cat_cols.txt', 'r') as file_1:
10
+ list_cat_cols = json.load(file_1)
11
+
12
+ with open('list_num_cols.txt', 'r') as file_2:
13
+ list_num_cols = json.load(file_2)
14
+
15
+ with open('model_scaler.pkl', 'rb') as file_3:
16
+ scaler = pickle.load(file_3)
17
+
18
+ with open('model_encoder.pkl', 'rb') as file_4:
19
+ encoder = pickle.load(file_4)
20
+
21
+ with open('model_lin_reg.pkl', 'rb') as file_5:
22
+ model_lin_reg = pickle.load(file_5)
23
+
24
+ def run():
25
+ # Membuat Form
26
+ with st.form(key='Form FIFA 2022'):
27
+ name = st.text_input('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', 50, 250, 180)
31
+ price = st.number_input('Price', min_value=0, max_value=10000000, 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=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
+ dribling = st.number_input('Dribling', 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
+ submited = 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': dribling,
59
+ 'DefendingTotal': defending,
60
+ 'PhysicalityTotal' : physicality
61
+ }
62
+
63
+ data_inf = pd.DataFrame([data_inf])
64
+ st.dataframe(data_inf)
65
+
66
+ if submited:
67
+ #Split between numerical columns and categorical columns
68
+ data_inf_num = data_inf[list_num_cols]
69
+ data_inf_cat = data_inf[list_cat_cols]
70
+ #Feature scaling and feature encoding
71
+ data_inf_num_scaled = scaler.transform(data_inf_num)
72
+ data_inf_cat_encoded = encoder.transform(data_inf_cat)
73
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
74
+ #Predict usiing linear regression
75
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
76
+ st.write('# Rating : ', str(int(y_pred_inf)))
77
+
78
+ if __name__ == '__main__':
79
+ run()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ pillow
6
+ numpy
7
+ scikit-learn==1.2.2