[Tennis] Decoding Roger Federer's play through data analysis❗
I analyzed Roger Federer's 🎾 play using machine learning.
I felt that data analysis makes the world of my hobbies look wider, deeper, and clearer...✨️
Anyone who loves tennis must have thought about this at least once.
"Federer's playing style has changed between the past and the present, right?"
"He was more aggressive in his prime."
"But is that 'true'? I kind of get it, but..."
This time, to put an end to this long-standing uncertainty, I decided to verify it with the best combination ofhobbies (tennis) × data analysis
.
Verification objective: I wanted to combine my hobby with Python.
The trigger was that I wanted to apply themachine learning knowledge I had worked so hard to learnto my private life.
As you can tell from my icon, I'm a 'Boo-chan' who loves tennis.
Since I was in junior high school, I often stayed up late to watch TV broadcasts of the Grand Slams (the four major global tournaments)...📺️
I also love "The Prince of Tennis" and collected all the volumes. I also like Inui-kun, the data man who appears in the series, haha.
Although not as much as Inui-kun, as a data scientist, I started to think, "I want to utilize data analysis for the sport of tennis"...
So, what I decided to tackle is...
Decoding the changes in Roger Federer's playing style from data❗️
is what I chose, haha.
Federer, whom anyone who has played tennis surely knows.
Because he has been active at the forefront of the tour for many years, his playing style has also followed various transitions.
There arevarious common theorieswhispered on the street, but are they true? I decided toverify them through data analysis❗️
Furthermore, in the second half, Icreated a tennis match outcome prediction modeland analyzedwhat factors supported Federer's victoriesduring his prime and his later years.

By the way, since the goal this time was to combine my hobby with Python and machine learning, please understand that there may be many points for experts to critique.
Analysis flow🔬
● Obtaining analysis data🔢
The stats for each match of professional tennis players, not limited to Federer, can be obtained from a site called "TennisAbstract".
Data for major players is well-preserved, and the data for a player who has been active for as long as Federer has a considerable volume. It is a sufficient amount for analysis💪
I would like to convert this data into CSV and analyze it with Python🖥️
(Please refer to the site for detailed data items and definitions.)
⬇️Tennis Abstract⬇️
https://www.tennisabstract.com/
● Setting analysis conditions⚖️
I divided his entire career into three era categories. The definitions are as follows.
Prime: 2003-2007
Later Years: 2017-2021
Others: Data outside the above
Additionally, missing values for each stat were filled using the mean for each column (fillna), but the mean was calculated for each of the three categories mentioned above. (If the mean were taken using data from both the prime and later years combined, the trends specific to each era would be diluted.)

● Selection of Win/Loss Prediction Model🧠
For the win/loss prediction model, I used a method called "LightGBM", which is said to be easy to handle, highly accurate, and computationally fast among machine learning models.
Roughly speaking...
It is a model that uses a large number of features (serve success rate, net play rate, rally length, etc.) to continuously sort data through "decision tree branching" to find which elements strongly contribute to the win or loss.
.
Also, LightGBM supports many learning features, and
feature importance (which elements had a strong influence)
SHAP (visualization of influence)
can also be visualized, so "the results are visually easy to understand" is its strength.

⬇️Overview of LightGBM⬇️
For those who want to learn about machine learning models, the following books are also recommended.
If you participate in Kaggle or SIGNATE while looking at these, your skills will improve rapidly⤴️
As an Amazon Associate, Yuru Papa Note earns income from qualifying purchases.
Analysis Results📒
① Changes in playing style by era
I visualized how the numerical values changed throughout his career by creating bar charts for each category.
The height of the bars for each year represents the average value of all matches played in that year for each category.
The images below highlight items that showed strong trend changes between his prime and his later years.
Looking at these results, for example, the following insights can be obtained.
In his later years, he hit drop shots more frequently than in his prime.
Rally aggressiveness also showed higher values in his later years.
▶Compared to his prime, in his later years,he might have been trying to take the initiative and end rallies earlier.

② Creation of a win/loss prediction model and factors contributing to wins by era
Additionally, I built a win/loss prediction model using data from each stat and the match results.
As mentioned earlier, the model uses LightGBM. Although the number of features is small, I intuitively selected the following eight. (I will mention this later, but it's a point for reflection...)
The model's learning results and accuracy are as follows.
Since there aren't tens of thousands of matches, the ROC curve looks angular, but the AUC score is 0.90 and the Accuracy is at a high level of 0.81.
...However, this was the result of cheating... Please see the final "Reflection" section...

In the model I created, the importance of each feature is shown in the figure below. (SHAP)
To interpret the figure, a high value for a feature is plotted in red, and a low value is plotted in blue. Also, the horizontal axis represents the magnitude of the contribution to the win/loss prediction; points further to the right contribute to a win, and points further to the left contribute to a loss.
For example, it is intuitively easy to understand that a low (blue) "winning percentage of important points" leads to a loss prediction (the plot is on the left).
Conversely, I thought that higher "2nd serve aggressiveness" and "rally aggressiveness" would be better for winning, but the results on the model were the exact opposite, which was surprising😯
This might be due to circumstances such as the fact that while Federer's "rally aggressiveness" improved in his later years, his match win rate declined.

I also thought that if I compared the SHAP diagrams between his prime and his later years, I might see differences in the features that contributed to wins in each era (i.e., changes in how he won), but there were no clear differences😅
This might be due to poor analysis methods, but I am interpreting it (conveniently) as the "characteristics of the sport of tennis"—specifically "how to reduce unforced errors and win important points without overexerting oneself"—being more prominent than changes in playing style. Lol

(Reference: How to read SHAP)
Impressions🔥
By combining my hobbies with Python, I was able to realize that data analysis can be applied to familiar subjects!
I also think I was able to look at the sport of tennis from a bird's-eye view once again⭐️
However, there are also reflections...⤵️
However, I think there was room for improvement in the analysis methods and feature selection...
That is, the point that the win-loss prediction model might be 'leaking*'.
Leak:A phenomenon where future information or answers that should not be known during training are accidentally mixed into the model.When this happens, the model produces
falsely high accuracy, making it completely useless in real-world applications. ▶ In short,
“it becomes a cheating model”.
In this example, the feature 'win rate on important points' was, frankly speaking, a 'result-based' metric that showed points had already been won.
Using such a feature means the prediction is just an obvious result—that 'winning many important points equals getting closer to victory' and 'losing many important points equals getting closer to defeat'.
An acquaintance pointed this out to me after I finished the entire analysis...😭
I need to carefully consider the conditions beforehand so I don't make such mistakes in professional work❗️
Everyone, please be careful...
Also, I didn't really perform feature engineering properly, and just selected features that seemed usefulbased on my intuition as a tennis player, so I should definitely scrutinize them more in professional practice... lol
💤Finally
The content this time was something I worked on when I was just starting out as a data scientist.
Looking back on it now, I have many thoughts... lol
Well, if I have time, I could try working on it again, or it might be interesting to create a win-loss prediction model using data from all players, not just Federer.
Since data analysis can be applied to various familiar problems, I thought I'd like to continue it as a lifelong hobby❗
“Why don't you try analyzing from this perspective too?” or “I want you to do this kind of analysis too!” — please let me know your opinions in the comments❗
See you later...💤
