danupurnomo commited on
Commit
4cbdb3e
·
verified ·
1 Parent(s): cb701c3

Upload 12 files

Browse files
model-deployment-038/__pycache__/eda.cpython-39.pyc ADDED
Binary file (1.66 kB). View file
 
model-deployment-038/__pycache__/prediction.cpython-39.pyc ADDED
Binary file (2.46 kB). View file
 
model-deployment-038/app.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ halaman = st.sidebar.selectbox('Pilih Halaman : ', ('EDA', 'Predict A Player'))
6
+
7
+ if halaman == 'EDA':
8
+ eda.run()
9
+
10
+ else:
11
+ prediction.run()
model-deployment-038/eda.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ from PIL import Image
5
+ import plotly.express as px
6
+ import matplotlib.pyplot as plt
7
+
8
+
9
+
10
+
11
+ def run():
12
+
13
+ # Membuat Title
14
+ st.title('Aplikasi Prediksi Rating Pemain FIFA 2022')
15
+
16
+ # Membuat Sub Header
17
+ st.subheader('Page mengenai Exploratory Data Analysis dari dataset FIFA 2022')
18
+
19
+ # Menambahkan Gambar
20
+ image = Image.open('soccer.jpg')
21
+ st.image(image, caption='FIFA 2022')
22
+
23
+ # Menambahkan Teks
24
+ st.write('Page ini dibuat oleh ***Danu Purnomo***')
25
+ st.write('# Halo')
26
+ st.write('## Halo')
27
+ st.write('### Halo')
28
+
29
+ # Show DataFrame
30
+ data = pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
31
+ st.dataframe(data)
32
+
33
+ # Membuat Bar Plot
34
+ st.write('#### Plot AttackingWorkRate')
35
+ fig = plt.figure(figsize=(15, 5))
36
+ sns.countplot(x='AttackingWorkRate', data=data)
37
+ st.pyplot(fig)
38
+
39
+ # Membuat Histogram
40
+ st.write('#### Histogram of Rating')
41
+ fig = plt.figure(figsize=(15, 5))
42
+ sns.histplot(data['Overall'], bins=30, kde=True)
43
+ st.pyplot(fig)
44
+
45
+ # Membuat Histogram Berdasarkan Input User
46
+ st.write('#### Histogram berdasarkan input user')
47
+ pilihan = st.selectbox('Pilih column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
48
+ fig = plt.figure(figsize=(15, 5))
49
+ sns.histplot(data[pilihan], bins=30, kde=True)
50
+ st.pyplot(fig)
51
+
52
+ # Membuat Plotly Plot
53
+ st.write('#### Plotly Plot - ValueEUR dengan Overall')
54
+ fig = px.scatter(data, x='ValueEUR', y='Overall', hover_data=['Name', 'Age'])
55
+ st.plotly_chart(fig)
56
+
57
+
58
+ if __name__ == '__main__':
59
+ run()
model-deployment-038/encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:983eb55948c85a6ed10ef56a1b9da005da09261c6fd6ac8f6d6dc38ea343e2ee
3
+ size 636
model-deployment-038/list_cat_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["AttackingWorkRate", "DefensiveWorkRate"]
model-deployment-038/list_num_cols.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ["Age", "Height", "Weight", "Price", "PaceTotal", "ShootingTotal", "PassingTotal", "DribblingTotal", "DefendingTotal", "PhysicalityTotal"]
model-deployment-038/model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9da3168e15beff16b96ae2a8d8f53f3f18ab3d9a660b803f5aec1811f1460249
3
+ size 595
model-deployment-038/prediction.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import json
4
+ import pandas as pd
5
+ import numpy as np
6
+
7
+ st.set_page_config(
8
+ page_title='FIFA 2022',
9
+ layout='wide',
10
+ initial_sidebar_state='expanded'
11
+ )
12
+
13
+ #Load files
14
+
15
+ with open('list_cat_cols.txt', 'r') as file_1:
16
+ list_cat_cols = json.load(file_1)
17
+
18
+ with open('list_num_cols.txt', 'r') as file_2:
19
+ list_num_cols = json.load(file_2)
20
+
21
+ with open('encoder.pkl', 'rb') as file_3:
22
+ encoder = pickle.load(file_3)
23
+
24
+ with open('scaler.pkl', 'rb') as file_4:
25
+ scaler = pickle.load(file_4)
26
+
27
+ with open('model_lin_reg.pkl', 'rb') as file_5:
28
+ model_lin_reg = pickle.load(file_5)
29
+
30
+
31
+ def run():
32
+ # Membuat Form
33
+ with st.form(key='form_fifa_2022'):
34
+ name = st.text_input('Name', value='')
35
+ age = st.number_input('Age', min_value=16, max_value=60, value=25, step=1, help='Usia Pemain')
36
+ weight = st.number_input('Weight', min_value=50, max_value=150, value=70)
37
+ height = st.slider('Height', 50, 250, 170)
38
+ price = st.number_input('Price', min_value=0, max_value=1000000000, value=0)
39
+ st.markdown('---')
40
+
41
+ attacking_work_rate = st.selectbox('AttackingWorkRate', ('Low', 'Medium', 'High'), index=0)
42
+ defensive_work_rate = st.radio('DefensiveWorkRate', ('Low', 'Medium', 'High'), index=1)
43
+ st.markdown('---')
44
+
45
+ pace = st.number_input('Kecepatan Lari', min_value=0, max_value=100, value=50)
46
+ shooting = st.number_input('Shooting', min_value=0, max_value=100, value=50)
47
+ passing = st.number_input('Passing', min_value=0, max_value=100, value=50)
48
+ dribbling = st.number_input('Dribbling', min_value=0, max_value=100, value=50)
49
+ defending = st.number_input('Defending', min_value=0, max_value=100, value=50)
50
+ physicality = st.number_input('Physicality', min_value=0, max_value=100, value=50)
51
+
52
+ submitted = st.form_submit_button('Predict')
53
+
54
+ data_inf = {
55
+ 'Name': name,
56
+ 'Age': age,
57
+ 'Height': height,
58
+ 'Weight': weight,
59
+ 'Price': price,
60
+ 'AttackingWorkRate': attacking_work_rate,
61
+ 'DefensiveWorkRate': defensive_work_rate,
62
+ 'PaceTotal': pace,
63
+ 'ShootingTotal': shooting,
64
+ 'PassingTotal': passing,
65
+ 'DribblingTotal': dribbling,
66
+ 'DefendingTotal': defending,
67
+ 'PhysicalityTotal': physicality
68
+ }
69
+ data_inf = pd.DataFrame([data_inf])
70
+ st.dataframe(data_inf)
71
+
72
+ if submitted:
73
+ #split between categorical and numerical
74
+ data_inf_num = data_inf[list_num_cols]
75
+ data_inf_cat = data_inf[list_cat_cols]
76
+
77
+ #Scaling and Encoding
78
+ data_inf_scaled = scaler.transform(data_inf_num)
79
+ data_inf_encoded = encoder.transform(data_inf_cat)
80
+ data_inf_final = np.concatenate([data_inf_scaled, data_inf_encoded], axis = 1)
81
+
82
+ #predict using linreg
83
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
84
+
85
+ st.write('# Rating : ', str(int(y_pred_inf)))
86
+
87
+
88
+
89
+
90
+
91
+ if __name__ == '__main__':
92
+ run()
model-deployment-038/requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ seaborn
5
+ matplotlib
6
+ plotly
7
+ pillow
8
+ scikit-learn==1.5.2
model-deployment-038/scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ecd617314342916b5738cf62db3df623b8a987d995cf442719cd4d5d4d55c7c
3
+ size 1096
model-deployment-038/soccer.jpg ADDED