AmrullahPasadi commited on
Commit
bbb165e
·
1 Parent(s): 03b5834

comit pertama

Browse files
Files changed (8) hide show
  1. eda.py +70 -0
  2. list_cat_cols.txt +1 -0
  3. list_num_cols.txt +1 -0
  4. main.py +9 -0
  5. model_encoder.pkl +3 -0
  6. model_lin_reg.pkl +3 -0
  7. model_scaler.pkl +3 -0
  8. prediction.py +83 -0
eda.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 - EDA',
10
+ layout = 'wide',
11
+ initial_sidebar_state='expanded'
12
+ )
13
+ #function Run eda
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 *Danu Purnomo*')
27
+ st.write('# Halo')
28
+ st.write('## Halo')
29
+ st.write('### Halo')
30
+
31
+ # Membuat Garis Lurus
32
+ st.markdown('---')
33
+
34
+ # Magic Syntax
35
+ '''
36
+ Pada page kali ini, penulis akan melakukan eksplorasi sederhana.
37
+ Dataset yang digunakan adalah dataset FIFA 2022.
38
+ Dataset ini berasal dari web sofifa.com.
39
+ '''
40
+
41
+ # Show DataFrame
42
+ data = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
43
+ st.dataframe(data)
44
+
45
+ # Membuat Barplot
46
+ st.write('#### Plot AttackingWorkRate')
47
+ fig = plt.figure(figsize=(15, 5))
48
+ sns.countplot(x='AttackingWorkRate', data=data)
49
+ st.pyplot(fig)
50
+
51
+ # Membuat Histogram
52
+ st.write('#### Histogram of Rating')
53
+ fig = plt.figure(figsize=(15, 5))
54
+ sns.histplot(data['Overall'], bins=30, kde=True)
55
+ st.pyplot(fig)
56
+
57
+ # Membuat Histogram Berdasarkan Input User
58
+ st.write('#### Histogram berdasarkan input user')
59
+ pilihan = st.selectbox('Pilih column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
60
+ fig = plt.figure(figsize=(15, 5))
61
+ sns.histplot(data[pilihan], bins=30, kde=True)
62
+ st.pyplot(fig)
63
+
64
+ # Membuat Plotly Plot
65
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
66
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Age'])
67
+ st.plotly_chart(fig)
68
+
69
+ if __name__ == '__main__':
70
+ 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,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ navigation =st.sidebar.radio('Pilih halaman : ', ('EDA','Prediction'),index=0)
6
+ if navigation == 'EDA':
7
+ eda.run()
8
+ else:
9
+ 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:3438706bd0366bca697182bbd80794617319e929556af5c80f2f69a5554b15a7
3
+ size 595
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:034959baab04bdd88c67ab44db7038187d1b4b7a68b23701a2414a6d58f081d9
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
+
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=100000000, value=0)
32
+ st.markdown('---')
33
+
34
+ attacking_work_rate = st.radio('Attacking Work Rate', ('Low', 'Medium', 'High'), index=2)
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
+ submitted = 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': dribbling,
59
+ 'DefendingTotal': defending,
60
+ 'PhysicalityTotal': physicality
61
+ }
62
+
63
+ data_inf = pd.DataFrame([data_inf])
64
+ st.dataframe(data_inf)
65
+
66
+ if submitted:
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
+
71
+ # Feature Scaling and Feature Encoding
72
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
73
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
74
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis=1)
75
+
76
+ # Predict using Linear Regression
77
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
78
+
79
+ st.write('# Rating : ', str(int(y_pred_inf)))
80
+
81
+
82
+
83
+