Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +73 -0
- requirements.txt +53 -0
- scaler.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pickle
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Importing necessary libraries
|
5 |
+
import pandas as pd
|
6 |
+
import numpy as np
|
7 |
+
import xgboost as xgb
|
8 |
+
|
9 |
+
|
10 |
+
from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor, VotingRegressor
|
11 |
+
from sklearn.model_selection import GridSearchCV, cross_val_score, KFold
|
12 |
+
from sklearn.metrics import mean_absolute_error
|
13 |
+
from sklearn.model_selection import train_test_split
|
14 |
+
from sklearn.preprocessing import StandardScaler
|
15 |
+
from sklearn.compose import ColumnTransformer
|
16 |
+
from sklearn.impute import SimpleImputer
|
17 |
+
|
18 |
+
from huggingface_hub import hf_hub_download
|
19 |
+
|
20 |
+
|
21 |
+
# Function to scale user input
|
22 |
+
def scale_input(user_input):
|
23 |
+
|
24 |
+
with open('scaler.pkl', 'rb') as file:
|
25 |
+
scaler = pickle.load(file)
|
26 |
+
|
27 |
+
user_input_df = pd.DataFrame([user_input], columns=feature_names)
|
28 |
+
scaled_input = scaler.transform(user_input_df)
|
29 |
+
return pd.DataFrame(scaled_input, columns=user_input_df.columns)
|
30 |
+
|
31 |
+
#download model from hugging face
|
32 |
+
model_path = hf_hub_download(repo_id="JemimaA/fifa-regression-ensemble", filename="ensemble_model.pkl")
|
33 |
+
|
34 |
+
# Load trained model
|
35 |
+
with open(model_path , 'rb') as file:
|
36 |
+
model = pickle.load(file)
|
37 |
+
|
38 |
+
|
39 |
+
# Feature names
|
40 |
+
feature_names = ['value_eur', 'age', 'potential', 'movement_reactions', 'wage_eur']
|
41 |
+
|
42 |
+
st.title('Player Rating Prediction App ⚽️')
|
43 |
+
|
44 |
+
# User input fields
|
45 |
+
st.sidebar.header('Player Features')
|
46 |
+
def user_input_features():
|
47 |
+
value_eur = st.sidebar.number_input('Value (EUR)', min_value=0, max_value=int(1e9), value=int(1e6))
|
48 |
+
wage_eur = st.sidebar.number_input('Wage (EUR)', min_value=0, max_value=int(1e9), value=int(1e6))
|
49 |
+
age = st.sidebar.slider('Age', 16, 40, 25)
|
50 |
+
potential = st.sidebar.slider('Potential', 1, 100, 50)
|
51 |
+
movement_reactions = st.sidebar.slider('Movement Reactions', 1, 100, 50)
|
52 |
+
data = {
|
53 |
+
'value_eur': value_eur,
|
54 |
+
'wage_eur': wage_eur,
|
55 |
+
'age': age,
|
56 |
+
'potential': potential,
|
57 |
+
'movement_reactions': movement_reactions
|
58 |
+
}
|
59 |
+
return data
|
60 |
+
|
61 |
+
input_data = user_input_features()
|
62 |
+
|
63 |
+
# Get predictions from model
|
64 |
+
st.subheader('Prediction')
|
65 |
+
scaled_input = scale_input(input_data)
|
66 |
+
prediction = model.predict(scaled_input)
|
67 |
+
st.write(f"Predicted Player Rating: {prediction[0]:.1f}")
|
68 |
+
|
69 |
+
# Explain model's prediction
|
70 |
+
if st.button('Explain Prediction'):
|
71 |
+
st.write('In this App, we are using a simple model that averages the predictions of 3 different models: Random Forest, Gradient Boosting and XGBoost to predict the player rating.')
|
72 |
+
st.write('The model was trained on the FIFA Male Legacy Players dataset, which contains data on players from the popular FIFA video game series. The dataset contains information on player attributes such as age, potential, value, etc. The model was trained to predict the player rating based on these attributes.')
|
73 |
+
st.write("This is a demo project and doesn't use any advanced model explanation techniques. Use with caution.")
|
requirements.txt
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.3.0
|
2 |
+
attrs==23.2.0
|
3 |
+
blinker==1.8.2
|
4 |
+
cachetools==5.3.3
|
5 |
+
certifi==2024.6.2
|
6 |
+
charset-normalizer==3.3.2
|
7 |
+
click==8.1.7
|
8 |
+
filelock==3.15.4
|
9 |
+
fsspec==2024.6.0
|
10 |
+
gitdb==4.0.11
|
11 |
+
GitPython==3.1.43
|
12 |
+
huggingface-hub==0.23.4
|
13 |
+
idna==3.7
|
14 |
+
Jinja2==3.1.4
|
15 |
+
joblib==1.4.2
|
16 |
+
jsonschema==4.22.0
|
17 |
+
jsonschema-specifications==2023.12.1
|
18 |
+
llvmlite==0.41.1
|
19 |
+
markdown-it-py==3.0.0
|
20 |
+
MarkupSafe==2.1.5
|
21 |
+
mdurl==0.1.2
|
22 |
+
numba==0.58.1
|
23 |
+
numpy==1.25.2
|
24 |
+
packaging==24.1
|
25 |
+
pandas==2.2.2
|
26 |
+
pillow==10.3.0
|
27 |
+
protobuf==5.27.1
|
28 |
+
pyarrow==16.1.0
|
29 |
+
pydeck==0.9.1
|
30 |
+
Pygments==2.18.0
|
31 |
+
python-dateutil==2.9.0.post0
|
32 |
+
pytz==2024.1
|
33 |
+
PyYAML==6.0.1
|
34 |
+
referencing==0.35.1
|
35 |
+
requests==2.32.3
|
36 |
+
rich==13.7.1
|
37 |
+
rpds-py==0.18.1
|
38 |
+
scikit-learn==1.2.2
|
39 |
+
scipy==1.13.1
|
40 |
+
six==1.16.0
|
41 |
+
sklearn-pandas==2.2.0
|
42 |
+
smmap==5.0.1
|
43 |
+
streamlit==1.36.0
|
44 |
+
tenacity==8.4.1
|
45 |
+
threadpoolctl==3.5.0
|
46 |
+
toml==0.10.2
|
47 |
+
toolz==0.12.1
|
48 |
+
tornado==6.4.1
|
49 |
+
tqdm==4.66.4
|
50 |
+
typing_extensions==4.12.2
|
51 |
+
tzdata==2024.1
|
52 |
+
urllib3==2.2.2
|
53 |
+
xgboost==2.0.3
|
scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:51618a02bb9ce18f78466307260c7634cf8b2114983b3472bb8275ce894fa2f0
|
3 |
+
size 718
|