{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "from sklearn.model_selection import train_test_split, StratifiedKFold, GridSearchCV\n", "from sklearn.metrics import confusion_matrix, mean_squared_error, mean_absolute_error, r2_score\n", "import xgboost\n", "import time\n", "from joblib import dump, load" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Load the data" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('final_data.txt')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['minute', 'position_name', 'shot_body_part_name', 'shot_technique_name',\n", " 'shot_type_name', 'shot_first_time', 'shot_one_on_one',\n", " 'shot_aerial_won', 'shot_deflected', 'shot_open_goal',\n", " 'shot_follows_dribble', 'shot_redirect', 'x1', 'y1',\n", " 'number_of_players_opponents', 'number_of_players_teammates', 'is_goal',\n", " 'angle', 'distance', 'x_player_opponent_Goalkeeper',\n", " 'x_player_opponent_8', 'x_player_opponent_1', 'x_player_opponent_2',\n", " 'x_player_opponent_3', 'x_player_teammate_1', 'x_player_opponent_4',\n", " 'x_player_opponent_5', 'x_player_opponent_6', 'x_player_teammate_2',\n", " 'x_player_opponent_9', 'x_player_opponent_10', 'x_player_opponent_11',\n", " 'x_player_teammate_3', 'x_player_teammate_4', 'x_player_teammate_5',\n", " 'x_player_teammate_6', 'x_player_teammate_7', 'x_player_teammate_8',\n", " 'x_player_teammate_9', 'x_player_teammate_10',\n", " 'y_player_opponent_Goalkeeper', 'y_player_opponent_8',\n", " 'y_player_opponent_1', 'y_player_opponent_2', 'y_player_opponent_3',\n", " 'y_player_teammate_1', 'y_player_opponent_4', 'y_player_opponent_5',\n", " 'y_player_opponent_6', 'y_player_teammate_2', 'y_player_opponent_9',\n", " 'y_player_opponent_10', 'y_player_opponent_11', 'y_player_teammate_3',\n", " 'y_player_teammate_4', 'y_player_teammate_5', 'y_player_teammate_6',\n", " 'y_player_teammate_7', 'y_player_teammate_8', 'y_player_teammate_9',\n", " 'y_player_teammate_10', 'x_player_opponent_7', 'y_player_opponent_7',\n", " 'x_player_teammate_Goalkeeper', 'y_player_teammate_Goalkeeper',\n", " 'shot_kick_off'],\n", " dtype='object')" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.columns" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | minute | \n", "position_name | \n", "shot_body_part_name | \n", "shot_technique_name | \n", "shot_type_name | \n", "shot_first_time | \n", "shot_one_on_one | \n", "shot_aerial_won | \n", "shot_deflected | \n", "shot_open_goal | \n", "... | \n", "y_player_teammate_6 | \n", "y_player_teammate_7 | \n", "y_player_teammate_8 | \n", "y_player_teammate_9 | \n", "y_player_teammate_10 | \n", "x_player_opponent_7 | \n", "y_player_opponent_7 | \n", "x_player_teammate_Goalkeeper | \n", "y_player_teammate_Goalkeeper | \n", "shot_kick_off | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "0 | \n", "Right Center Forward | \n", "Right Foot | \n", "Normal | \n", "Open Play | \n", "False | \n", "False | \n", "False | \n", "False | \n", "False | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "False | \n", "
1 | \n", "5 | \n", "Right Center Forward | \n", "Left Foot | \n", "Normal | \n", "Open Play | \n", "False | \n", "False | \n", "False | \n", "False | \n", "False | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "False | \n", "
2 | \n", "5 | \n", "Center Midfield | \n", "Right Foot | \n", "Half Volley | \n", "Open Play | \n", "True | \n", "False | \n", "False | \n", "False | \n", "False | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "False | \n", "
3 | \n", "5 | \n", "Left Center Midfield | \n", "Right Foot | \n", "Normal | \n", "Open Play | \n", "False | \n", "False | \n", "False | \n", "False | \n", "False | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "False | \n", "
4 | \n", "5 | \n", "Right Center Back | \n", "Left Foot | \n", "Normal | \n", "Open Play | \n", "True | \n", "False | \n", "False | \n", "False | \n", "False | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "False | \n", "
5 rows × 66 columns
\n", "\n", " | Training MAE | \n", "Training RMSE | \n", "Training R2 | \n", "Testing MAE | \n", "Testing RMSE | \n", "Testing R2 | \n", "Training Time (mins) | \n", "
---|---|---|---|---|---|---|---|
Model Name | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
XG Boost | \n", "0.09934 | \n", "0.31518 | \n", "0.03828 | \n", "0.10366 | \n", "0.32197 | \n", "0.01251 | \n", "31.93709 | \n", "