clara22 commited on
Commit
c716dce
1 Parent(s): 816012c

Upload 8 files

Browse files
Files changed (8) hide show
  1. app.py +32 -0
  2. eda.py +89 -0
  3. list_num_columns.txt +1 -0
  4. model_encoder.pkl +3 -0
  5. model_lin_reg.pkl +3 -0
  6. model_scaler.pkl +3 -0
  7. prediction.py +94 -0
  8. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+ from PIL import Image
5
+
6
+ img1 = Image.open('balls.jpg')
7
+
8
+ page = st.sidebar.selectbox('Choose Page: ',
9
+ ('Landing Page','Data Exploration','Data Prediction'))
10
+
11
+ if page == 'Landing Page':
12
+ st.title('FIFA 2022 Player Rating Prediction')
13
+ st.write('')
14
+ st.write('Name : Yosef')
15
+ st.write('Batch : HCK-007')
16
+ st.write('Objective : Ovuvwevewe Onyetevwevwe Ugwemugwem Ossass')
17
+ st.write('')
18
+ st.write('Please select menu on the left bar')
19
+ st.write('')
20
+ # st.image(img1, caption="Balls")
21
+ with st.expander('Background Dataset'):
22
+ st.caption('Dataset background explaination')
23
+ with st.expander('Problem Statement'):
24
+ st.caption('Saya mau uang')
25
+ with st.expander('SPONSOR'):
26
+ st.caption('FIFA')
27
+ # st.image(img1)
28
+
29
+ elif page == 'Data Exploration':
30
+ eda.run()
31
+ else:
32
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ import seaborn as sns
6
+ import plotly.express as px
7
+ from PIL import Image
8
+
9
+ st.set_page_config(
10
+ page_title='FIFA 2022 Prediction',
11
+ layout='wide',
12
+ initial_sidebar_state='expanded')
13
+
14
+ def run():
15
+ st.title("FIFA 2022 Exploratory Data Analysis")
16
+
17
+ st.subheader("Analysis Data for 2022 Football Player by FIFA")
18
+
19
+ # # Add image
20
+ # image = Image.open('socerfield.jpg')
21
+ # st.image(image, caption='FIFA 2022')
22
+
23
+ # Create Outline
24
+ st.write("# Outline A")
25
+ st.write("## Outline A.1")
26
+ st.write("### Outline A.1.a")
27
+ st.write("# Outline B")
28
+
29
+ # Create markdown line
30
+ st.markdown("---")
31
+
32
+ # Show datafreame
33
+ st.write("# Dataframe FIFA 2022")
34
+ df = pd.read_csv('https://raw.githubusercontent.com/FTDS-learning-materials/phase-1/master/w1/P1W1D1PM%20-%20Machine%20Learning%20Problem%20Framing.csv')
35
+ st.dataframe(df)
36
+ st.markdown("---")
37
+
38
+ # Visualization
39
+ st.write('# Visualization')
40
+
41
+ # Create Barplot
42
+ st.write('## Attacking Work Rate Plot')
43
+ fig = plt.figure(figsize=(15,5))
44
+ sns.countplot(x='AttackingWorkRate', data=df)
45
+ st.pyplot(fig)
46
+ st.write('Explanation')
47
+
48
+ # Create Histplot
49
+ st.write('## Histogram of Rating')
50
+ fig = plt.figure(figsize=(15,5))
51
+ sns.histplot(x='Overall',
52
+ data=df,
53
+ bins=50,
54
+ kde=True) # Add line
55
+ st.pyplot(fig)
56
+ st.write("Explanation")
57
+
58
+ # Create scatterplot
59
+ st.write('## Scatterplot of Weight and Height')
60
+ fig = plt.figure(figsize=(15,5))
61
+ sns.scatterplot(x='Weight',
62
+ y='Height',
63
+ data=df)
64
+ st.pyplot(fig)
65
+ st.write("Explanation")
66
+
67
+ # Create histogram by user input
68
+ st.write('# Visualization by User Input')
69
+ choice = st.radio('Select Feature: ',
70
+ ('Age','Weight','Height','ShootingTotal'),
71
+ help='Select the feature you want!')
72
+ fig = plt.figure(figsize=(15,5))
73
+ sns.histplot(df[choice],
74
+ bins=35,
75
+ kde=True) # Add line
76
+ st.pyplot(fig)
77
+ st.write('Explaination')
78
+
79
+ # Create plotly plot
80
+ st.write('# Plotly Plot - Player Price againts Rating')
81
+ fig = px.scatter(df,
82
+ x='ValueEUR',
83
+ y='Overall',
84
+ hover_data=['Name','Age'])
85
+ st.plotly_chart(fig)
86
+ st.write('Explain!')
87
+
88
+ if __name__ == '__main__':
89
+ run()
list_num_columns.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:4eaee6b8047336daf8785247ccea985d34ddc47bdad5747cf963acdd7eefa1e7
3
+ size 617
model_lin_reg.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ecadb5a4600e367fba8e82068775352bcaa3cb260acd2f04c4b7949f0887047c
3
+ size 595
model_scaler.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f07647394f461fe77584b199f6a6f0cc70f06cd5274f04f3830873e66e8bce24
3
+ size 1096
prediction.py ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import json
4
+ import pandas as pd
5
+ import numpy as np
6
+
7
+ # Load model
8
+ with open('list_num_columns.txt', 'r') as file_1:
9
+ list_num_cols = json.load(file_1)
10
+
11
+ with open('list_cat_columns.txt', 'r') as file_2:
12
+ list_cat_cols = json.load(file_2)
13
+
14
+ with open('model_scaler.pkl', 'rb') as file_3:
15
+ model_scaler = pickle.load(file_3)
16
+
17
+ with open('model_encoder.pkl', 'rb') as file_4:
18
+ model_encoder = pickle.load(file_4)
19
+
20
+ with open('model_lin_reg.pkl', 'rb') as file_5:
21
+ model_lin_reg = pickle.load(file_5)
22
+
23
+ def run():
24
+ with st.form('form_fifa_2022'):
25
+ name = st.text_input('Name', value='', help='Player name')
26
+ age = st.number_input('Age',
27
+ min_value=12,
28
+ max_value=48,
29
+ value=28,
30
+ step=1,
31
+ help='Player age')
32
+ weight = st.number_input('Weight',
33
+ min_value=30,
34
+ max_value=100,
35
+ value=80,
36
+ help='Player weight')
37
+ height = st.number_input('Height',
38
+ min_value=140,
39
+ max_value=210,
40
+ value=180,
41
+ help='Player height')
42
+ price = st.slider('Price', 0, 200000000, 0)
43
+ st.markdown('---')
44
+ defense = st.radio('Defending Work Rate',
45
+ ('Low','Medium','High'),
46
+ index=1)
47
+ attack = st.radio('Attacking Work Rate',
48
+ ('Low','Medium','High'),
49
+ index=1)
50
+ st.markdown('---')
51
+ pace = st.number_input('Pace', 0, 100, 50)
52
+ shoot = st.number_input('Shooting', 0, 100, 50)
53
+ passing = st.number_input('Passing', 0, 100, 50)
54
+ dribble = st.number_input('Dribbling', 0, 100, 50)
55
+ defend = st.number_input('Defending', 0, 100, 50)
56
+ physical = st.number_input('Phisicality', 0, 100, 50)
57
+ st.markdown('---')
58
+ submitted = st.form_submit_button('PREDICT')
59
+
60
+ data_inf = {
61
+ 'Name': name,
62
+ 'Age': age,
63
+ 'Weight': weight,
64
+ 'Height': height,
65
+ 'Price': price,
66
+ 'AttackRate': attack,
67
+ 'DefenseRate': defense,
68
+ 'PaceTotal': pace,
69
+ 'ShootingTotal': shoot,
70
+ 'PassingTotal': passing,
71
+ 'DribblingTotal': dribble,
72
+ 'DefendingTotal': defend,
73
+ 'PhysicalityTotal': physical
74
+ }
75
+ data_inf = pd.DataFrame([data_inf])
76
+ st.dataframe(data_inf)
77
+
78
+ if submitted:
79
+ # Numeric-Categoric split
80
+ data_inf_num = data_inf[list_num_cols]
81
+ data_inf_cat = data_inf[list_cat_cols]
82
+ # Numeric
83
+ data_inf_num_scaled = model_scaler.transform(data_inf_num)
84
+ # Categoric
85
+ data_inf_cat_encoded = model_encoder.transform(data_inf_cat)
86
+ # Concatenate
87
+ data_inf_final = np.concatenate([data_inf_num_scaled,data_inf_cat_encoded], axis=1)
88
+ # Predict
89
+ y_inf_pred = model_lin_reg.predict(data_inf_final)
90
+ # Show prediction
91
+ st.write('# Rating: ', str(int(y_inf_pred)))
92
+
93
+ if __name__ == '__main__':
94
+ run()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ numpy
4
+ matplotlib
5
+ seaborn
6
+ plotly.express
7
+ scikit-learn