Skip to content

Commit

Permalink
fix plot
Browse files Browse the repository at this point in the history
  • Loading branch information
mathisdrn committed Apr 10, 2024
1 parent a1dfd9c commit 325daae
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 45 deletions.
83 changes: 77 additions & 6 deletions src/02 Exploratory data analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,47 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"head_coach = pd.read_csv('data/head_coach.csv', dtype = {'HeadCoach' : 'str'}, parse_dates=['Appointed', 'EndDate'])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Seasons: 2014-2023\n",
"Leagues: Premier League, La Liga, Ligue 1, Bundesliga, Serie A\n",
"Number of matches: 14873\n",
"Number of teams: 161\n",
"Number of teams without coach: 96\n",
"Percentage of matches without coach: 44.97%\n",
"Number of appointments: 398\n",
"Number of unique coaches: 233\n",
"Number of teams per coach: HeadCoach n_team\n",
"178 Rafael Benítez 4\n",
"142 Maurizio Sarri 4\n",
"223 Unai Emery 4\n",
"176 Quique Setién 4\n",
"81 Giuseppe Iachini 4\n",
".. ... ...\n",
"93 Javi Gracia 1\n",
"94 Javier Calleja 1\n",
"95 Jean-Louis Gasset 1\n",
"96 Jean-Luc Vasseur 1\n",
"116 Louis van Gaal 1\n",
"\n",
"[233 rows x 2 columns]\n"
]
}
],
"source": [
"min_season = match_results['Date'].dt.year.min()\n",
"max_season = match_results['Date'].dt.year.max()\n",
Expand All @@ -182,7 +220,18 @@
"n_team_no_coach = match_results.groupby(['Team'])['HeadCoach'].apply(lambda x: x.isnull().all()).sum()\n",
"perc_match_no_coach = match_results['HeadCoach'].isnull().sum() / len(match_results) * 100\n",
"n_unique_coach = match_results['HeadCoach'].nunique()\n",
"n_unique_coach_records = match_results.groupby(['HeadCoach'])['Team'].nunique().reset_index(name='n_team').sort_values(by='n_team', ascending=False)"
"n_appointments = len(head_coach)\n",
"n_unique_coach_records = match_results.groupby(['HeadCoach'])['Team'].nunique().reset_index(name='n_team').sort_values(by='n_team', ascending=False)\n",
"\n",
"print(f\"Seasons: {min_season}-{max_season}\")\n",
"print(f\"Leagues: {leagues}\")\n",
"print(f\"Number of matches: {n_match}\")\n",
"print(f\"Number of teams: {n_team}\")\n",
"print(f\"Number of teams without coach: {n_team_no_coach}\")\n",
"print(f\"Percentage of matches without coach: {perc_match_no_coach:.2f}%\")\n",
"print(f\"Number of appointments: {n_appointments}\")\n",
"print(f\"Number of unique coaches: {n_unique_coach}\")\n",
"print(f\"Number of teams per coach: {n_unique_coach_records}\")"
]
},
{
Expand Down Expand Up @@ -351,18 +400,40 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 13,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average home goals: 1.51\n",
"Average away goals: 1.18\n",
"Difference in average goals: -21.52%\n",
"Home win percentage: 0.43\n",
"Away win percentage: 0.29\n",
"Difference in win percentage: -48.77%\n",
"Draw percentage: 0.26\n"
]
}
],
"source": [
"home_goal = match_results[match_results['isHome']]['Goals'].mean()\n",
"away_goal = match_results[~match_results['isHome']]['Goals'].mean()\n",
"diff_goal_perc = ((away_goal - home_goal) / home_goal) * 100\n",
"\n",
"home_win = match_results[match_results['isHome']]['Result'].value_counts(normalize=True)['win']\n",
"away_win = match_results[~match_results['isHome']]['Result'].value_counts(normalize=True)['win']\n",
"diff_win_perc = ((away_win - home_win) / home_win) * 100\n",
"home_draw = match_results[match_results['isHome']]['Result'].value_counts(normalize=True)['draw']"
"diff_win_perc = ((away_win - home_win) / away_win) * 100\n",
"home_draw = match_results[match_results['isHome']]['Result'].value_counts(normalize=True)['draw']\n",
"\n",
"print(f\"Average home goals: {home_goal:.2f}\")\n",
"print(f\"Average away goals: {away_goal:.2f}\")\n",
"print(f\"Difference in average goals: {diff_goal_perc:.2f}%\")\n",
"print(f\"Home win percentage: {home_win:.2f}\")\n",
"print(f\"Away win percentage: {away_win:.2f}\")\n",
"print(f\"Difference in win percentage: {diff_win_perc:.2f}%\")\n",
"print(f\"Draw percentage: {home_draw:.2f}\")"
]
},
{
Expand Down
78 changes: 39 additions & 39 deletions src/04 Statistical analysis.ipynb

Large diffs are not rendered by default.

0 comments on commit 325daae

Please sign in to comment.