fadyabila commited on
Commit
a55cc32
1 Parent(s): 79cfd09

First Commit

Browse files
eda.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Melebarkan visualisasi untuk memaksmalkan browser
9
+ st.set_page_config(
10
+ page_title='FIFA 2022',
11
+ layout='wide',
12
+ initial_sidebar_state='expanded'
13
+ )
14
+
15
+ def run():
16
+ # Membuat title
17
+ st.title('Fifa 2022 Player Rating Prediction')
18
+
19
+ # Membuat Sub Headrer
20
+ st.subheader('EDA untuk Analisa Dataset FIFA 2022')
21
+
22
+ # Menambahkan Gambar
23
+ image = Image.open('soccer.jpg')
24
+ st.image(image, caption='FIFA 2022')
25
+
26
+ # Menambahkan Deskripsi
27
+ st.write('Page ini dibuat oleh ***Fadya***')
28
+ st.write('# Halo')
29
+ st.write('## Halo')
30
+ st.write('### Halo')
31
+
32
+ # Membuat Garis Lurus
33
+ st.markdown('---')
34
+
35
+ # Magic Syntax
36
+ '''
37
+ Pada page kali ini, penulis akan melakukan eksplorasi sederhana.
38
+ Dataset yang digunakan adalah dataset FIFA 2022.
39
+ Dataset ini berasal dari web sofifa.com.
40
+ '''
41
+
42
+ # Show DataFrame
43
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
44
+ st.dataframe(data)
45
+
46
+ # Membuat Barplot
47
+ st.write('#### Plot AttackingMorkRate')
48
+ fig = plt.figure(figsize=(15,5))
49
+ sns.countplot(x='AttackingWorkRate', data=data)
50
+ st.pyplot(fig)
51
+
52
+ # Membuat Histogram
53
+ st.write('#### Histogram of Rating')
54
+ fig = plt.figure(figsize=(15,5))
55
+ sns.histplot(data['Overall'], bins=30, kde=True)
56
+ st.pyplot(fig)
57
+
58
+ # Membuat Plotly Plot
59
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
60
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Age'])
61
+ st.plotly_chart(fig)
62
+
63
+ # Membuat Histogram Berdasarkan Input User
64
+ st.write('#### Histogram berdasarkan Input User')
65
+ pilihan = st.selectbox('Pilih Column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
66
+ fig = plt.figure(figsize=(15,5))
67
+ sns.histplot(data[pilihan], bins=30, kde=True)
68
+ st.pyplot(fig)
69
+
70
+ if __name__ == '__main__':
71
+ 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', 'Project 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: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,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ with st.form(key='form_fifa_2022'):
26
+ name = st.text_input('Name', value='')
27
+ age = st.number_input('Age', min_value=16, max_value=60, value=25, step=1, help='Usia Pemain')
28
+ weight = st.number_input('Weight', min_value=50, max_value=150, value=70)
29
+ height = st.slider('Height', 50, 250, 170)
30
+ price = st.number_input('Price', min_value=0, max_value=1000000000, value=0)
31
+ st.markdown('---')
32
+
33
+ attacking_work_rate = st.selectbox('AttackingWorkRate', ('Low', 'Medium', 'High'), index=1)
34
+ defensive_work_rate = st.radio('DefensiveWorkRate', ('Low', 'Medium', 'High'), index=1)
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
+
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
+ data_inf_num
71
+
72
+ # Feature Scaling and Feature Encoding
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
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
79
+ st.write('# Rating : ', str(int(y_pred_inf)))
80
+
81
+ if __name__ == '__main__':
82
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # Berisi daftar library yang kita butuhkan
2
+
3
+ streamlit
4
+ pandas
5
+ seaborn
6
+ matplotlib
7
+ numpy
8
+ scikit-learn==1.2.1