notbeekay commited on
Commit
c83b148
·
verified ·
1 Parent(s): 3b2f884

Upload 12 files

Browse files
Model_Deployment.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Model_Deployment_Inference.ipynb ADDED
@@ -0,0 +1,357 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "id": "NnI3VscLsD6z"
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "#import library\n",
12
+ "\n",
13
+ "import pickle\n",
14
+ "import json\n",
15
+ "import pandas as pd\n",
16
+ "import numpy as np"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": 2,
22
+ "metadata": {
23
+ "colab": {
24
+ "base_uri": "https://localhost:8080/"
25
+ },
26
+ "id": "ZuS5HPBkBbZ4",
27
+ "outputId": "7561ff89-4d83-48c3-b809-28e633e72508"
28
+ },
29
+ "outputs": [
30
+ {
31
+ "name": "stdout",
32
+ "output_type": "stream",
33
+ "text": [
34
+ "Name: scikit-learn\n",
35
+ "Version: 1.5.1\n",
36
+ "Summary: A set of python modules for machine learning and data mining\n",
37
+ "Home-page: https://scikit-learn.org\n",
38
+ "Author: \n",
39
+ "Author-email: \n",
40
+ "License: new BSD\n",
41
+ "Location: /opt/anaconda3/envs/phase1/lib/python3.12/site-packages\n",
42
+ "Requires: joblib, numpy, scipy, threadpoolctl\n",
43
+ "Required-by: feature-engine\n"
44
+ ]
45
+ }
46
+ ],
47
+ "source": [
48
+ "!pip show scikit-learn"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "markdown",
53
+ "metadata": {
54
+ "id": "bDmKBK0SolkE"
55
+ },
56
+ "source": [
57
+ "### load model"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": 3,
63
+ "metadata": {
64
+ "id": "4aqmhcqinrlU"
65
+ },
66
+ "outputs": [],
67
+ "source": [
68
+ "#Load model\n",
69
+ "\n",
70
+ "with open('list_cat_cols.txt', 'r') as file_1:\n",
71
+ " list_cat_col = json.load(file_1)\n",
72
+ "\n",
73
+ "with open('list_num_cols.txt', 'r') as file_2:\n",
74
+ " list_num_col = json.load(file_2)\n",
75
+ "\n",
76
+ "with open('model_encoder.pkl', 'rb') as file_3:\n",
77
+ " model_encoder = pickle.load(file_3)\n",
78
+ "\n",
79
+ "with open('model_scaler.pkl', 'rb') as file_4:\n",
80
+ " model_scaler = pickle.load(file_4)\n",
81
+ "\n",
82
+ "with open('model_lin_reg.pkl', 'rb') as file_5:\n",
83
+ " model_lin_reg = pickle.load(file_5)"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "markdown",
88
+ "metadata": {
89
+ "id": "Ra7wa9DyokUs"
90
+ },
91
+ "source": [
92
+ "###Inferece"
93
+ ]
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "execution_count": 4,
98
+ "metadata": {
99
+ "colab": {
100
+ "base_uri": "https://localhost:8080/",
101
+ "height": 100
102
+ },
103
+ "id": "_6zz1wBVoYFG",
104
+ "outputId": "e7389c1d-6944-45e7-a7d2-311fdc3b022d"
105
+ },
106
+ "outputs": [
107
+ {
108
+ "data": {
109
+ "text/html": [
110
+ "<div>\n",
111
+ "<style scoped>\n",
112
+ " .dataframe tbody tr th:only-of-type {\n",
113
+ " vertical-align: middle;\n",
114
+ " }\n",
115
+ "\n",
116
+ " .dataframe tbody tr th {\n",
117
+ " vertical-align: top;\n",
118
+ " }\n",
119
+ "\n",
120
+ " .dataframe thead th {\n",
121
+ " text-align: right;\n",
122
+ " }\n",
123
+ "</style>\n",
124
+ "<table border=\"1\" class=\"dataframe\">\n",
125
+ " <thead>\n",
126
+ " <tr style=\"text-align: right;\">\n",
127
+ " <th></th>\n",
128
+ " <th>Name</th>\n",
129
+ " <th>Age</th>\n",
130
+ " <th>Height</th>\n",
131
+ " <th>Weight</th>\n",
132
+ " <th>Price</th>\n",
133
+ " <th>AttackingWorkRate</th>\n",
134
+ " <th>DefensiveWorkRate</th>\n",
135
+ " <th>PaceTotal</th>\n",
136
+ " <th>ShootingTotal</th>\n",
137
+ " <th>PassingTotal</th>\n",
138
+ " <th>DribblingTotal</th>\n",
139
+ " <th>DefendingTotal</th>\n",
140
+ " <th>PhysicalityTotal</th>\n",
141
+ " </tr>\n",
142
+ " </thead>\n",
143
+ " <tbody>\n",
144
+ " <tr>\n",
145
+ " <th>0</th>\n",
146
+ " <td>Hana</td>\n",
147
+ " <td>50</td>\n",
148
+ " <td>180</td>\n",
149
+ " <td>70</td>\n",
150
+ " <td>30000000</td>\n",
151
+ " <td>Medium</td>\n",
152
+ " <td>Low</td>\n",
153
+ " <td>60</td>\n",
154
+ " <td>80</td>\n",
155
+ " <td>30</td>\n",
156
+ " <td>70</td>\n",
157
+ " <td>60</td>\n",
158
+ " <td>80</td>\n",
159
+ " </tr>\n",
160
+ " </tbody>\n",
161
+ "</table>\n",
162
+ "</div>"
163
+ ],
164
+ "text/plain": [
165
+ " Name Age Height Weight Price AttackingWorkRate DefensiveWorkRate \\\n",
166
+ "0 Hana 50 180 70 30000000 Medium Low \n",
167
+ "\n",
168
+ " PaceTotal ShootingTotal PassingTotal DribblingTotal DefendingTotal \\\n",
169
+ "0 60 80 30 70 60 \n",
170
+ "\n",
171
+ " PhysicalityTotal \n",
172
+ "0 80 "
173
+ ]
174
+ },
175
+ "execution_count": 4,
176
+ "metadata": {},
177
+ "output_type": "execute_result"
178
+ }
179
+ ],
180
+ "source": [
181
+ " #Create new data\n",
182
+ "#Gunakan keseluruhan data\n",
183
+ "\n",
184
+ "data_inf = {\n",
185
+ " 'Name' : 'Hana',\n",
186
+ " 'Age' : 50,\n",
187
+ " 'Height' : 180,\n",
188
+ " 'Weight' : 70,\n",
189
+ " 'Price' : 30000000,\n",
190
+ " 'AttackingWorkRate' : 'Medium',\n",
191
+ " 'DefensiveWorkRate' : 'Low',\n",
192
+ " 'PaceTotal' :60,\n",
193
+ " 'ShootingTotal': 80,\n",
194
+ " 'PassingTotal' : 30,\n",
195
+ " 'DribblingTotal' :70,\n",
196
+ " 'DefendingTotal' :60,\n",
197
+ " 'PhysicalityTotal':80,\n",
198
+ "}\n",
199
+ "\n",
200
+ "data_inf = pd.DataFrame([data_inf])\n",
201
+ "data_inf"
202
+ ]
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "execution_count": 5,
207
+ "metadata": {
208
+ "colab": {
209
+ "base_uri": "https://localhost:8080/",
210
+ "height": 80
211
+ },
212
+ "id": "JHPUX35kpjyL",
213
+ "outputId": "a30b72c5-036a-46fe-e0dd-1a61788d0dc5"
214
+ },
215
+ "outputs": [
216
+ {
217
+ "data": {
218
+ "text/html": [
219
+ "<div>\n",
220
+ "<style scoped>\n",
221
+ " .dataframe tbody tr th:only-of-type {\n",
222
+ " vertical-align: middle;\n",
223
+ " }\n",
224
+ "\n",
225
+ " .dataframe tbody tr th {\n",
226
+ " vertical-align: top;\n",
227
+ " }\n",
228
+ "\n",
229
+ " .dataframe thead th {\n",
230
+ " text-align: right;\n",
231
+ " }\n",
232
+ "</style>\n",
233
+ "<table border=\"1\" class=\"dataframe\">\n",
234
+ " <thead>\n",
235
+ " <tr style=\"text-align: right;\">\n",
236
+ " <th></th>\n",
237
+ " <th>Age</th>\n",
238
+ " <th>Height</th>\n",
239
+ " <th>Weight</th>\n",
240
+ " <th>Price</th>\n",
241
+ " <th>PaceTotal</th>\n",
242
+ " <th>ShootingTotal</th>\n",
243
+ " <th>PassingTotal</th>\n",
244
+ " <th>DribblingTotal</th>\n",
245
+ " <th>DefendingTotal</th>\n",
246
+ " <th>PhysicalityTotal</th>\n",
247
+ " </tr>\n",
248
+ " </thead>\n",
249
+ " <tbody>\n",
250
+ " <tr>\n",
251
+ " <th>0</th>\n",
252
+ " <td>50</td>\n",
253
+ " <td>180</td>\n",
254
+ " <td>70</td>\n",
255
+ " <td>30000000</td>\n",
256
+ " <td>60</td>\n",
257
+ " <td>80</td>\n",
258
+ " <td>30</td>\n",
259
+ " <td>70</td>\n",
260
+ " <td>60</td>\n",
261
+ " <td>80</td>\n",
262
+ " </tr>\n",
263
+ " </tbody>\n",
264
+ "</table>\n",
265
+ "</div>"
266
+ ],
267
+ "text/plain": [
268
+ " Age Height Weight Price PaceTotal ShootingTotal PassingTotal \\\n",
269
+ "0 50 180 70 30000000 60 80 30 \n",
270
+ "\n",
271
+ " DribblingTotal DefendingTotal PhysicalityTotal \n",
272
+ "0 70 60 80 "
273
+ ]
274
+ },
275
+ "execution_count": 5,
276
+ "metadata": {},
277
+ "output_type": "execute_result"
278
+ }
279
+ ],
280
+ "source": [
281
+ "#split between numerical and categorical columns\n",
282
+ "\n",
283
+ "data_inf_num = data_inf[list_num_col]\n",
284
+ "data_inf_cat = data_inf[list_cat_col]\n",
285
+ "data_inf_num"
286
+ ]
287
+ },
288
+ {
289
+ "cell_type": "code",
290
+ "execution_count": 6,
291
+ "metadata": {
292
+ "id": "Yligyt0up4Ld"
293
+ },
294
+ "outputs": [],
295
+ "source": [
296
+ "#feature scaling and encoding\n",
297
+ "\n",
298
+ "data_inf_num_scaled = model_scaler.transform(data_inf_num)\n",
299
+ "data_inf_cat_encoded = model_encoder.transform(data_inf_cat)\n",
300
+ "data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": 7,
306
+ "metadata": {
307
+ "colab": {
308
+ "base_uri": "https://localhost:8080/"
309
+ },
310
+ "id": "5EBS6wQYqUfb",
311
+ "outputId": "a29e15a7-27dd-4284-8152-9ba9a69a1916"
312
+ },
313
+ "outputs": [
314
+ {
315
+ "data": {
316
+ "text/plain": [
317
+ "array([82.7433109])"
318
+ ]
319
+ },
320
+ "execution_count": 7,
321
+ "metadata": {},
322
+ "output_type": "execute_result"
323
+ }
324
+ ],
325
+ "source": [
326
+ "#predict using linear reg model\n",
327
+ "\n",
328
+ "y_pred_inf = model_lin_reg.predict(data_inf_final)\n",
329
+ "y_pred_inf"
330
+ ]
331
+ }
332
+ ],
333
+ "metadata": {
334
+ "colab": {
335
+ "provenance": [],
336
+ "toc_visible": true
337
+ },
338
+ "kernelspec": {
339
+ "display_name": "Python 3",
340
+ "name": "python3"
341
+ },
342
+ "language_info": {
343
+ "codemirror_mode": {
344
+ "name": "ipython",
345
+ "version": 3
346
+ },
347
+ "file_extension": ".py",
348
+ "mimetype": "text/x-python",
349
+ "name": "python",
350
+ "nbconvert_exporter": "python",
351
+ "pygments_lexer": "ipython3",
352
+ "version": "3.12.4"
353
+ }
354
+ },
355
+ "nbformat": 4,
356
+ "nbformat_minor": 0
357
+ }
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ page = st.sidebar.selectbox('Choose page: ', ('EDA', 'Prediction'))
6
+
7
+ if page == 'EDA':
8
+ eda.run()
9
+ else:
10
+ prediction.run()
bola.jpeg ADDED
eda.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ def run():
9
+
10
+ # Create title
11
+ st.title('FIFA 2022 Player Rating Prediction')
12
+
13
+ # Create subheader
14
+ st.subheader('EDA untuk Analys FIFA Rating 2022')
15
+
16
+ # Insert image
17
+ image = Image.open('bola.jpeg')
18
+ st.image(image, caption = 'FIFA 2022')
19
+
20
+ # Create text
21
+ st.write('This page is written by Brenda')
22
+
23
+ # Bold
24
+ st.write('**Tes**')
25
+
26
+ # Italic
27
+ st.write('*Tes*')
28
+
29
+ # Make font size
30
+ st.write('# Halo')
31
+ st.write('## Halo')
32
+
33
+ # Make a straight line
34
+ st.markdown('---')
35
+
36
+ # Load and show datafrane
37
+ df = pd.read_csv('https://raw.githubusercontent.com/ardhiraka/FSDS_Guidelines/master/p1/v3/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
38
+ st.dataframe(df)
39
+
40
+ # Make a barplot
41
+ st.write('#### Plot AttackingWorkRate')
42
+ fig = plt.figure(figsize=(15,5))
43
+ sns.countplot(x = 'AttackingWorkRate', data = df)
44
+ st.pyplot(fig)
45
+
46
+ # Make a histogram
47
+ st.write('#### Histogram of Rating')
48
+ fig = plt.figure(figsize = (15,5))
49
+ sns.histplot(df['Overall'], bins = 30, kde = True)
50
+ st.pyplot(fig)
51
+
52
+ # Make a histogram based on user input
53
+ st.write('#### Histogram based on user input')
54
+ option = st.selectbox('Choose a column', ('Age', 'Weight', 'ShootingTotal'))
55
+ fig = plt.figure(figsize = (15,5))
56
+ sns.histplot(df[option], bins = 30, kde = True)
57
+ st.pyplot(fig)
58
+
59
+ # Make visualisation with plotly plot
60
+ st.write('#### Plotly plot - ValueEUR Vs Overall (Rating)')
61
+ fig = px.scatter(df, x = 'ValueEUR', y = 'Overall', hover_data = ['Name', 'Age'])
62
+ st.plotly_chart(fig)
63
+
64
+ if __name__ == '__main__':
65
+ 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"]
model_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df0b8c0b58197ff3f7593e599ac7d22ed2e7872305c34b0285e90cb9af9a0422
3
+ size 636
model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38351e88399327d968436b0310e0606bdb1c4dbd479204fd1bc83388eb3c20e2
3
+ size 595
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:113fcf87816e12fe474fc1568f74fa2d57f4c4f54588a6ee065329b4cfcaad16
3
+ size 1096
prediction.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_col = json.load(file_1)
11
+
12
+ with open('list_num_cols.txt', 'r') as file_2:
13
+ list_num_col = json.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('model_scaler.pkl', 'rb') as file_4:
19
+ model_scaler = 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
+
26
+ # Make form to fill data
27
+ with st.form('form_fifa_2022'):
28
+ # Use text_input
29
+ name = st.text_input('Name: ', value = '')
30
+ # Use number_input
31
+ age = st.number_input('Age: ', value = 25, min_value = 15, max_value = 60, help = 'Fill with player age')
32
+ height = st.number_input('Height', value = 170, min_value = 150, max_value = 250)
33
+ # Use a slider
34
+ weight = st.slider('Weight: ', min_value = 50, max_value = 100, value = 70)
35
+ # Price
36
+ price = st.number_input('Price: ', value = 0, min_value = 0)
37
+ st.markdown('---')
38
+
39
+ attacking_work_rate = st.selectbox('Attacking Work Rate: ', ('Low', 'Medium', 'High'), index= 1)
40
+ defensive_work_rate = st.selectbox('Defensive Work Rate: ', ('Low', 'Medium', 'High'), index= 1)
41
+
42
+ pace = st.number_input('Pace: ', min_value =0, max_value = 100, value = 10)
43
+ shooting = st.number_input('Shooting: ', min_value =0, max_value = 100, value = 10)
44
+ passing = st.number_input('Passing: ', min_value =0, max_value = 100, value = 10)
45
+ dribbling = st.number_input('Dribbling: ', min_value =0, max_value = 100, value = 10)
46
+ defending = st.number_input('Defending: ', min_value =0, max_value = 100, value = 10)
47
+ physicality = st.number_input('Physicality: ', min_value =0, max_value = 100, value = 10)
48
+
49
+ # Define submit button form
50
+ submitted = st.form_submit_button('Predict')
51
+
52
+ data_inf = {
53
+ 'Name' : name,
54
+ 'Age' : age,
55
+ 'Height' : height,
56
+ 'Weight' : weight,
57
+ 'Price' : price,
58
+ 'AttackingWorkRate' : attacking_work_rate,
59
+ 'DefensiveWorkRate' :defensive_work_rate,
60
+ 'PaceTotal' : pace,
61
+ 'ShootingTotal': shooting,
62
+ 'PassingTotal' : passing,
63
+ 'DribblingTotal' : dribbling,
64
+ 'DefendingTotal' : defending,
65
+ 'PhysicalityTotal': physicality,
66
+ }
67
+
68
+ data_inf = pd.DataFrame([data_inf])
69
+ st.dataframe(data_inf)
70
+
71
+ if submitted:
72
+ # Split
73
+ data_inf_num = data_inf[list_num_col]
74
+ data_inf_cat = data_inf[list_cat_col]
75
+
76
+ # Scaling, Encoding, Concatenate
77
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
78
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
79
+ data_inf_final = np.concatenate([data_inf_num_scaled, data_inf_cat_encoded], axis = 1)
80
+
81
+ # Predict
82
+ y_pred_inf = model_lin_reg.predict(data_inf_final)
83
+
84
+ st.write('## Rating: ', str(int(y_pred_inf)))
85
+
86
+ if __name__ == '__main__':
87
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ numpy
6
+ scikit-learn == 1.3.2
7
+ Pillow
8
+ plotly