-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph9.py
59 lines (41 loc) · 2 KB
/
graph9.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from abrev import team_abbreviations
from data.league_tables.process_tables import points_diff
from data.transfers.process_transfers import transfers_five_year_table
# from scipy import stats
'''
Point Difference vs. Net Transfer balance, Year to Year (2018-2023)
'''
#spending of each team, with all years indexed by the year.
#loop through 5 year table, and use each years transfer value in evaluating
#x points will be transfer spending.
# y points will be point difference between years.
# (spending, point difference) for any given year.
# NOTE this only includes current premier league teams
# NOTE teams which have been in the league in non-consecutive seasons use the transfer spending of the first season. If the time period
# was longer, this would need to be adjusted, but since its relatively short, this still makes sense.
#OR I will just factor teams which have been in the league all 5 years.
x_points = []
y_points = []
for entry in transfers_five_year_table:
cur_team = entry["Team"]
if points_diff.__contains__(cur_team):
for diff in points_diff[cur_team]:
y_points.append(diff[0]) #point difference in season diff[1]
#index by the season of transfer spending we need.
x_points.append(-entry[diff[1]])
# print(x,y)
plt.scatter(x_points,y_points)
plt.title("Point Difference vs. Net Transfer balance, Year to Year (2018-2023)")
plt.xlabel("Net Transfer Balance(€ in millions)")
plt.ylabel("Point Difference between two Consecutive Seasons")
# Calculate coefficients for the line of best fit
b, a = np.polyfit(x_points, y_points, deg=1)
# Create a polynomial function from the coefficients
line_of_best_fit = np.poly1d((b, a))
print("For 100 million a club spends, next season's point total is predicted to decrease by ", 100*b, ".")
# Generate y-values for each x-value using the line of best fit
plt.plot(x_points, line_of_best_fit(x_points), color='green')
plt.show()