Arya99 commited on
Commit
b20dbaa
1 Parent(s): 5a60eac

first commit

Browse files
P1W1D1PM - Machine Learning Problem Framing.csv ADDED
The diff for this file is too large to render. See raw diff
 
eda.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ import plotly.express as px
7
+ from PIL import Image
8
+
9
+ st.set_page_config(
10
+ page_title="FIFA 2022 Player Rating Prediction",
11
+ layout='wide',
12
+ initial_sidebar_state='expanded'
13
+ )
14
+ def run(): # Agar bisa dipanggil oleh code main.
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
+ # Membuat Deskripsi
22
+ st.write('Page ini dibuat oleh *Ardiansyah Arya Salvinia')
23
+
24
+ # Menambahkan Gambar
25
+ image = Image.open('joshua-hoehne-8ZvTRSRdsOA-unsplash.jpg')
26
+ st.image(image, caption='FIFA 2022')
27
+
28
+ # Menambahkan Garis Lurus
29
+ st.markdown('---')
30
+
31
+ # Magic Syntax untuk menuliskan text beberapa baris
32
+ '''
33
+ Pada page kali ini, penulis akan melakukan eksplorasi sederhana.
34
+ Dataset yang digunakan adalah dataset FIFA 2022.
35
+ Dataset ini berasal dari web sofifa.com.
36
+ '''
37
+
38
+ # Show Dataframe
39
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
40
+ st.dataframe(data)
41
+
42
+ # Membuat BarPlot
43
+ st.write('### Plot AttackingWorkRate')
44
+ fig = plt.figure(figsize=(15,5))
45
+ sns.countplot(x='AttackingWorkRate',data=data)
46
+ st.pyplot(fig)
47
+
48
+ # Membuat Histogram
49
+ st.write('### Histogram of Rating')
50
+ fig = plt.figure(figsize=(15,5))
51
+ sns.histplot(data['Overall'], bins=30, kde=True)
52
+ st.pyplot(fig)
53
+
54
+ # Membuat Histogram Berdasarkan Input User
55
+ st.write('#### Histogram Berdasarkan Input User')
56
+ pilihan = st.radio(' Pilih Column : ', ('Age','Weight','Height','ShootingTotal'))
57
+ fig = plt.figure(figsize=(15,5))
58
+ sns.histplot(data[pilihan], bins=30, kde=True)
59
+ st.pyplot(fig)
60
+
61
+ # Membuat Plotly Plot
62
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
63
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name','Age'])
64
+ st.plotly_chart(fig)
65
+
66
+ if __name__ == '__main__': # Agar python bisa dibuka standalone tanpa membuka main.
67
+ 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
+ # Digunakan sebagai pusat code yang akan digunakan user.
2
+ import streamlit as st
3
+ import eda
4
+ import prediction
5
+
6
+ navigation = st.sidebar.selectbox('Pilh Halaman : ', ('EDA', 'Predict A Player'))
7
+
8
+ if navigation == '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:0487ce8b546fe0a6b798cb570bf6f876b6f7c687b42a3a1d4e690b791b95fcdb
3
+ size 1361
model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08f34fed46db68589436b95a9f085a5b38f053b2d98dac710a9fe5310bed7328
3
+ size 861
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f66a44b8a7e687aae2805b4ea993c7eaf9eefd8b77f5e85b9fd9a1e7d4ee69c1
3
+ size 1590
prediction.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ import plotly.express as px
7
+ from PIL import Image
8
+
9
+ # Load All Files
10
+
11
+ import joblib
12
+ import json
13
+
14
+ # Load All Files
15
+ with open('model_lin_reg.pkl', 'rb') as file_1:
16
+ model_lin_reg = joblib.load(file_1)
17
+
18
+ with open('model_scaler.pkl', 'rb') as file_2:
19
+ model_scaler = joblib.load(file_2)
20
+
21
+ with open('model_encoder.pkl', 'rb') as file_3:
22
+ model_encoder = joblib.load(file_3)
23
+
24
+ with open('list_num_cols.txt', 'r') as file_4:
25
+ list_num_cols = json.load(file_4)
26
+
27
+ with open('list_cat_cols.txt', 'r') as file_5:
28
+ list_cat_cols = json.load(file_5)
29
+
30
+
31
+ def run(): # Agar bisa dipanggil oleh main.
32
+ # Membuat Form
33
+ with st.form(key='form_parameters'):
34
+ name = st.text_input('Name', value='') # Value = nilai default
35
+ age = st.number_input('Age', min_value=16, max_value=60, value=25, step=1, help='Usia Pemain') # Help deskripsi kolom form
36
+ weight = st.number_input('Weight', min_value=50, max_value=150, value=70)
37
+ height = st.number_input('Height',min_value=50, max_value=250, value=170)
38
+ # Bisa menggunakan untuk slider `price = st.slider('Price', 0,100000000)`
39
+ price = st.number_input('Price', min_value=0, max_value=1000000000, value=0)
40
+ st.markdown('---')
41
+
42
+ attacking_work_rate = st.selectbox('AttackingWorkRate', ('Low','Medium','High'), index=1)
43
+ defensive_work_rate = st.selectbox('DefensiveWorkRate', ('Low','Medium','High'), index=2)
44
+ st.markdown('---')
45
+
46
+ pace = st.number_input('Pace', min_value=0, max_value=100, value=50)
47
+ shooting = st.number_input('Shooting', min_value=0, max_value=100, value=50)
48
+ passing = st.number_input('Passing', min_value=0, max_value=100, value=50)
49
+ dribbling = st.number_input('Dribbling', min_value=0, max_value=100, value=50)
50
+ defending = st.number_input('Defending', min_value=0, max_value=100, value=50)
51
+ physicality = st.number_input('Physicality', min_value=0, max_value=100, value=50)
52
+
53
+
54
+ submitted = st.form_submit_button('Predict')
55
+
56
+ data_inf = { # Label harus sama dengan CSV, variabel bebas.
57
+ 'Name' : name,
58
+ 'Age' : age,
59
+ 'Height' : height,
60
+ 'Weight' : weight,
61
+ 'Price' : price,
62
+ 'AttackingWorkRate' : attacking_work_rate,
63
+ 'DefensiveWorkRate' : defensive_work_rate,
64
+ 'PaceTotal' : pace,
65
+ 'ShootingTotal' : shooting,
66
+ 'PassingTotal' : passing,
67
+ 'DribblingTotal' : dribbling,
68
+ 'DefendingTotal' : defending,
69
+ 'PhysicalityTotal' : physicality
70
+ }
71
+
72
+ data_inf = pd.DataFrame([data_inf])
73
+ st.dataframe(data_inf)
74
+
75
+ if submitted:
76
+ # Split between Numerical Columns and Categorical Columns
77
+ data_inf_num = data_inf[list_num_cols]
78
+ data_inf_cat = data_inf[list_cat_cols]
79
+
80
+
81
+ # Feature Scaling and Feature Encoding
82
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
83
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
84
+
85
+
86
+ # Concate Numerical Columns and Categorical Columns
87
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
88
+
89
+ # Predict using Linear regression
90
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
91
+
92
+ st.write('# Rating : ', str(int(y_pred_inf)))
93
+
94
+ if __name__ == '__main__': # Agar python bisa dibuka standalone tanpa membuka main.
95
+ run()
requirement.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ streamlit
2
+ numpy
3
+ seaborn
4
+ matplotlib
5
+ joblib
6
+ scikit-learn==1.0.2