Load the required library appropriately.
import pandas as pd
import scipy as sp
import matplotlib.pyplot as plt
import seaborn as sns
Please put them in the same directory. Upload if colaboratry
team = pd.read_csv('Teams.csv')
If you read it with seaborn without selecting the feature amount, it will be a huge amount, so select the feature amount.
teams = teams[['yearID','teamID', 'Rank', 'W','L', 'H','SB','SO','RA','SV', 'BB', 'HBP', 'AB', 'SF', 'HR', '2B', '3B']]
Visualize the correlation matrix with a seaborn heatmap.
colormap = plt.cm.RdBu
plt.figure(figsize=(16,10))
plt.title('Pearson Correlation of Features', y=1.05, size=15)
sns.heatmap(teams2.corr(),linewidths=0.1,vmax=1.0,
square=True, cmap=colormap, linecolor='white', annot=True)
It can be confirmed that HR (number of home runs) and SO (strikeout rate) are increasing with each passing year. What can be considered from this is the flyball revolution. It is a well-known fact that the flyball revolution has increased the strikeout rate and the number of home runs. This can also be confirmed from this data. Also, SV (the increase in the number of saves shows that the pitcher division of labor system was established by the times)
By clarifying the relationship between the total number of years and the number of wins, I would like to investigate whether there is a difference between the past and the present, which is the most efficient choice.
salaries = pd.read_csv('Salaries.csv')
teams = teams.set_index(['yearID'])
teams.head()
salaries_by_yearID_teamID = salaries.groupby(['yearID', 'teamID'])['salary'].sum()
teams = teams.join(salaries_by_yearID_teamID)
plt.subplot(1,2,1)
plt.scatter(teams['salary'][2001], teams['W'][2001])
plt.title('2001')
plt.subplot(1,2,2)
plt.scatter(teams['salary'][2013], teams['W'][2013])
plt.title('2013')
A positive correlation can be confirmed in 2013 than in 2001. This may be because the technology to detect the abilities of athletes has evolved from 2001.
I was able to recall the evolutionary history of Sabermetrics while analyzing it with data. The flyball revolution had a major impact on baseball.
Recommended Posts