<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sergio Pessoa on Medium]]></title>
        <description><![CDATA[Stories by Sergio Pessoa on Medium]]></description>
        <link>https://medium.com/@sslp23?source=rss-a9bd5bd0981c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IMtxTF6tdwvSWpPb</url>
            <title>Stories by Sergio Pessoa on Medium</title>
            <link>https://medium.com/@sslp23?source=rss-a9bd5bd0981c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:54:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sslp23/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A systematic review of FIFA World Cup prediction methods]]></title>
            <link>https://pub.aimind.so/a-systematic-review-of-fifa-world-cup-prediction-methods-cef4ba7689ec?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cef4ba7689ec</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Wed, 10 Jun 2026 01:41:25 GMT</pubDate>
            <atom:updated>2026-06-13T13:44:46.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wr-fAERyUBmqF9Zk" /><figcaption>Photo by <a href="https://unsplash.com/@fznsr_?utm_source=medium&amp;utm_medium=referral">Fauzan Saari</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of my favourite hobbies as a Data Scientist is, undoubtedly, analysing and creating models to understand the chances of each team in a big tournament. Previously, I already published here two stories about this and my experience: “<a href="https://medium.com/latinxinai/predicting-fifa-2022-world-cup-with-machine-learning-640f1d2d7e98">Predicting FIFA 2022 World Cup with Machine Learning</a>” and “<a href="http://An ML — Poisson model to predict UEFA Euro 2024">An ML — Poisson model to predict UEFA Euro 2024</a>”.</p><p>Both projects were important to me, each in its own way. The first opened the door to work with real sports analytics data, and the second helped me form strong connections in the industry.</p><p>Of course, the life and work of a Data Scientist in the previous 4 years had a lot of changes. AI coding agents brought a significant gain in productivity to Data Science practitioners, and this gave me some ideas to make a deeper and more ambitious project. I had three goals:</p><ul><li><strong>Build 5 different models</strong>: one statistical model (Ordered Logit), one hybrid model (Poisson with parameter calculated with Machine Learning), two purely ML models (CatBoost and XGBoost) and one ensemble model (Hybrid-Poisson + CatBoost + XGBoost).</li><li><strong>Simulate and backtest</strong> the last 5 World Cups for each model, and try to answer what the best approach is for Football prediction.</li><li>Use the optimal model to <strong>simulate and predict</strong> the FIFA World Cup 2026 (the <strong>most </strong>fun part!).</li></ul><p>That’s why I say my idea this time isn’t to simply predict the champion, but also to create a <strong>systematic method to understand which approach is the best to tackle this problem: how to find the best prediction on a football match</strong>. After finding the optimal model based on previous World Cup analysis, we can apply this to the World Cup 2026 and get some insights.</p><p>A project of this depth was only possible through the help and use of AI coding agents. Since this is a hobby and non-profitable project, my idea was to test them to see if they can produce good, reliable code.</p><h3>Dataset &amp; Feature Selection</h3><p>As in the previous projects, the base dataset used is <a href="https://www.kaggle.com/datasets/martj42/international-football-results-from-1872-to-2017">International football results from 1872 to 2026</a>, which is available on Kaggle.</p><p>From this dataset, I’ve calculated performance metrics, such as a team goal difference moving average in the past 20 and 5 games, for example. Also, for this time, I included as candidate features some metrics related to the previous World Cup only performance: World Cup games played, World Cup goals scored, and World Cup best round achieved.</p><p>Initially, my idea was to use the FIFA Rankings, as I’ve always used them, and then I scraped this information from <a href="https://www.transfermarkt.com/">Transfermarkt</a>.</p><p>I’ve also built two ratings this time: <a href="https://www.eloratings.net/">ELO Ratings</a> and PI-Ratings. Both calculations are explained in my repo.</p><p>Besides that, I’ve also got from Kaggle the history of <a href="https://www.kaggle.com/datasets/davidcariboo/player-scores?select=player_valuations.csv">Transfermarkt Market Values</a> for all players in their database, and calculated the sum and median of top-20 players from each nation with the highest Market Values as a proxy for team quality. Of course, my idea would be to get only the market values of players called to play in the World Cup, but this would make it impossible to build the backtesting I was projecting, because I would need to scrape the data of Transfermarkt Market Value for each international match available in my database.</p><p>These features described were all feature candidates for the <strong>Machine Learning models and the ML-Poisson hybrid model</strong>, in which I would predict the Poisson parameter using an ML model. The CatBoost model also had as a feature candidate the Confederations of each national team, due to its good support for <strong>categorical features</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQ8sj8XI0Kmyu8J9fXQgaQ.png" /></figure><p>The first analysis I’ve made was to understand which features had a good predictive power. Clearly, the ratings (ELO, PI and FIFA rankings) were above all other metrics based on their predictive power. My goal now would be to see if they had collinearity (which I highly suspected):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a06MGL2ZVh9oJwVGHtQzxA.png" /></figure><p>FIFA points, PI-Ratings and ELO were highly correlated. My idea was to use only ELO, since it had the highest predictive power.</p><p>Market Values had a good predictive power, too. I used only the total sum for each national team instead of the median, because they were also highly correlated.</p><p>The other metrics used were all performance metrics. All metrics were used in the format of a difference. So, for example, in a prediction of a winner from Team A vs Team B, we used the ELO Rating difference from Team A&#39;s ELO and Team B&#39;s ELO.</p><h3><strong>Models</strong></h3><h4>Ordered Logit</h4><p>My first modelling test was to use the Ordered Logit, a statistical model not so much used by Data Scientists in Football, but with some positive results.</p><p>This statistical model treats outcomes (away_win &lt; draw &lt; home_win) as ordered thresholds on a latent “strength gap” variable. The strength gap is a weighted sum of four rating/market-value features; two learned thresholds separate the three outcome zones.</p><p>To calculate the strength gap, I’ve used four parameters: ELO difference and FIFA ranking points difference, Market Value sum difference and Market Value log-ratio of both teams.</p><h4>Machine Learning — Poisson</h4><p>This model is the same I’ve used on my previous project (<a href="https://medium.com/ai-mind-labs/a-machine-learning-poisson-model-to-predict-uefa-euro-2024-d7b22bacc06e">An ML — Poisson model to predict UEFA Euro 2024</a>). It’s a two-stage hybrid model where an XGBoost Regressor predicts the expected goal Poisson parameter (λ), and I use these predicted values in a Dixon-Coles matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vULD-QT7VC1sWLdRZ-Er_Q.png" /><figcaption>ML-Poisson model architecture</figcaption></figure><p>To build the regressor model, I’ve used as features ELO difference, Market Value difference, log-ratio, World Cup best round, total games, and goals scored difference, and Attacking (goals scored moving average, 5 and 20 games, points won in previous matches) and Defensive (goals conceded and goals difference, 5 and 20 games moving average), both weighted by opponent’s level.</p><h4>XGBoost</h4><p>XGBoost is the state-of-the-art for solving many tabular data problems, so worth testing it on this problem. The set of features used was:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*NAMlxATBJi7RLOh_T631WQ.png" /></figure><h4>CatBoost</h4><p>CatBoost is another popular method when using ML to predict Football results, and it has very good support for categorical features, which allows the use of confederation as model input. The set of features used was:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*6Mg_PNCcG0TkWgHOEMvmNg.png" /></figure><h4><strong>Ensemble</strong></h4><p>The latest is an Ensemble model combining CatBoost, XGBoost, and ML-Poisson. This Ensemble consisted of an equal-weight average of the three models to test whether diversity across modelling approaches benefits predictions.</p><h4>Evaluation Methods</h4><p>To evaluate each model, I used <strong>Accuracy</strong>, <strong>Log-Loss </strong>and <strong>RPS</strong> (Ranked Probability Score). Usually, RPS is considered the metric to be minimised when dealing with the Football prediction problem. However, in this specific case, I also wanted to maximise the accuracy: for me, one of the best applications of these projects is to test if you correctly predicted the winners, so let’s try to achieve maximum accuracy also.</p><h3>Backtest &amp; Evaluation</h3><p>The backtest procedure will be used to evaluate each of the 5 models. For each FIFA World Cup, from 2006 to 2022, I trained each model with the same parameters using the data before the WC and predicted the results of each edition. After that, we choose the model that minimises the RPS and maximises the accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iAvxJYk8BIX1P4v6m5Dm7w.png" /><figcaption>Cumulative RPS across 5 World Cup editions</figcaption></figure><p>The first analysis consists of evaluating the cumulative RPS across five different World Cup editions. At the end, the Ensemble and CatBoost models end up with almost the same value (0.192) for RPS.</p><p>Based on the <a href="https://thexgfootballclub.substack.com/p/which-machine-learning-models-perform">2017 Soccer Prediction Challenge results</a>, a 0.192 RPS would be among the best models. Of course, these results are very related to how easy it is to predict the event. This is clear when we check the results individually for each World Cup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_Sp41nfywTYc0vIcVCO8w.png" /></figure><p>Individually, WC 2006 is by far the easiest edition to predict, with the highest values for accuracy, and the lowest for RPS and Log-Loss. World Cup 2026 was the most unpredictable, in general. This raises a question: Is Football becoming more unpredictable?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CagyGAtieG1j4mrjC9x0Rw.png" /></figure><p>The cumulative accuracy chart shows us, again, that CatBoost has the second-highest value, close to the first, Ordered Logit. Based on this, I decided to use CatBoost as the model to simulate the World Cup 2026.</p><p>Also, we can see that, among the two Gradient Boosting methods tested, XGBoost and CatBoost, the second has a clear advantage over the first, ending up with better metrics in most of the World Cup editions. The Ensemble and ML-Poisson models have good RPS, but low accuracy, while the Ordered Logit model stands out in terms of accuracy, but registered a not-so-good RPS.</p><h3>Simulation</h3><p>Now, let’s go to the fun part: simulating FIFA World Cup 2026. The model used in the simulation was the CatBoost, with the same parameters used in the Backtesting. We started with the group phase:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lbo6hq4YtzMc3wQ_xocZXQ.png" /></figure><p>The model predicted two unexpected results that drew my attention: a draw between the Ivory Coast and Germany and a Panama win against Ghana. The second one was the subject of a long investigation from me, but it is directly related to the awful preparation that Ghana had during this World Cup cycle, which resulted in a very bad Elo rating for them.</p><p>Germany, also, isn’t well rated by the Machine Learning model: the European nation isn’t predicted to be the first in Group E, staying behind Ecuador in this simulation. Anyway, I think this would be an advance compared to their last two World Cup participations.</p><p>Another thing that is nearly impossible to capture using a Machine Learning or Statistical model is the logistical problems that Iran will face. Although they are a team with good previous results and a history at World Cups, I think they will struggle to make these two wins predicted by the model in the group phase, as they will face a very tough logistics challenge that consists of entering the USA on the day of the match and leaving a few hours after the game. It’s likely that it impacts their game, which highlights how multifactorial a Football match can be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bddBc-b5CoFhV1gzliV_ng.png" /></figure><p>As developed on the previous projects, we can also see the network chart of the playoff analysis. The final simulation shows Spain winning the title against Argentina.</p><p>As a Brazilian, I hope the model makes a mistake as it happened at the WC 2022! In this simulation, we lost in the quarter-finals against England (which is a clear indicator that we didn’t use the total number of World Cup titles as a feature).</p><p>In contrast to the group stage, no big surprise happened in the simulated playoffs. All results were a win by the consensus favourite (which we know doesn’t happen in real life).</p><p>After that, I decided to use the model predictions and apply a 10,000 iterations Monte Carlo Simulation, to extract the probabilities of the title for each National team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*99o75DGnxWj2BPPJsFhCaw.png" /></figure><p>Spain is coming up as the big favourites, followed by Argentina, England and France. Spain&#39;s chances are boosted by a very high ELO Rating and a well-valued team. Also, I think Spain has an easier expected trajectory than other favourites: if everything comes as expected, their first game against a World Champion will only happen in the semi-finals.</p><p>After France, we have a gap of 3% to the next favourites: Brazil and Portugal. The Netherlands and, surprisingly, Ecuador come up next. These Ecuador chances drew my attention, and they are mainly a result of a very good ELO Rating and a high Market Value for many players in their squad.</p><h3>Conclusion</h3><p>Whenever a big Football competition comes, predicting the champion with data becomes my next project. As a Data Scientist and Football enthusiast, it’s always an easy and pleasant way of testing and improving my skills.</p><p>This time, I feel very happy after concluding this project. Firstly, it helped me to integrate many of my daily practices and routines with AI Coding Agents, which are helping me to improve productivity across several projects.</p><p>Alongside this, the productivity gain enabled me to push the boundaries of the project: traditionally, I chose one model and tested it against the competition. This time, I tested 5 different models across 5 World Cup editions, using the best to simulate FIFA World Cup 2026 and extracting champion probabilities using a Monte Carlo Simulation.</p><p>And, finally, I started this project very late. On May 4, I decided to build everything of this, and it was a very ambitious project that made me glad to conclude.</p><p>Of course, my goal here is always to use data to understand the probabilities and chances of each National team in the competition, instead of simply trying to predict the final champion. Football is a highly unpredictable sport, and, as a Data Scientist working deeply in the field in the past years, I advise all readers to focus more on the probabilistic part of the article rather than interpreting this as a pure “guess” of the champion.</p><p>I’m happy to share on my <a href="https://github.com/sslp23/world-cup-sim-26/tree/main">GitHub the project repository</a> with anyone who wants to understand how each step worked. Also, you can reach me through my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><h4>A Message from AI Mind</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*5Wm7sOfTpe5DEbhg.gif" /></figure><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://pub.aimind.so/">AI Mind Publication</a></li><li>🧠 Improve your <a href="https://www.aimind.so/prompt-generator?utm_source=pub&amp;utm_medium=message">AI prompts effortlessly and FREE</a></li><li><strong>🧰 Discover </strong><a href="https://www.aimind.so/?utm_source=pub&amp;utm_medium=message"><strong>Intuitive AI Tools</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cef4ba7689ec" width="1" height="1" alt=""><hr><p><a href="https://pub.aimind.so/a-systematic-review-of-fifa-world-cup-prediction-methods-cef4ba7689ec">A systematic review of FIFA World Cup prediction methods</a> was originally published in <a href="https://pub.aimind.so/">AI Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Machine Learning — Poisson model to predict UEFA Euro 2024]]></title>
            <link>https://pub.aimind.so/a-machine-learning-poisson-model-to-predict-uefa-euro-2024-d7b22bacc06e?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7b22bacc06e</guid>
            <category><![CDATA[stats]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Fri, 14 Jun 2024 02:24:50 GMT</pubDate>
            <atom:updated>2024-06-15T18:01:16.744Z</atom:updated>
            <content:encoded><![CDATA[<h3>An ML — Poisson model to predict UEFA Euro 2024</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fqnDCKKTgbkNhC_M" /><figcaption>Photo by <a href="https://unsplash.com/@piak?utm_source=medium&amp;utm_medium=referral">Josip Ivankovic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>On the eve of the 2022 World Cup, I published the article “<a href="https://medium.com/latinxinai/predicting-fifa-2022-world-cup-with-machine-learning-640f1d2d7e98">Predicting FIFA 2022 World Cup with Machine Learning</a>” here. This article was my first, and still my most-read article on Medium. It was so important that I changed my career to work as a Data Scientist focused on Sports Analytics, a role that I’ve been performing since the end of 2022. But, even with the positive repercussions, I believed that many things in that model could be improved.</p><p>Working in Sports Analytics made me study a lot of the state of the art in the area, and prediction of results had a lot of research. Most of them, use <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson Distribution</a> to predict the correct result or the winner of the game. I found a lot of studies that aimed to improve the Poisson Distribution by selecting the optimal λ parameter (the Poisson’s Expected Value). Most of them built a kind of Attacking and Defending strengths, or things like that, to avoid using the simple Goal Average/Moving Average. I always thought these approaches were limited, and decided to do my own model using a Machine Learning regression model, to find the λ parameter for the home team and away team, and, then calculate the probability of each of them winning the game.</p><p>To find the best λ parameter, my regression model would predict the expected number of goals the Home and Away teams would do in a match. The predicted value for each of them would be used as λ in the Poisson distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*0gKIRtA53NwbVAE7nVFZMQ.png" /><figcaption>Poisson Distribution formula</figcaption></figure><p>Why do that for the Euro? First, I like international competitions which take place every 4 years. Also, international competitions have a parameter that can be combined in the simple and usual calculation of “Attacking Strengths”, which is the National Team’s FIFA Ranking.</p><h3><strong>Data Source</strong></h3><p>I used the same dataset of my predictions for the 2022 World Cup: <a href="https://www.kaggle.com/datasets/martj42/international-football-results-from-1872-to-2017">past games</a> and <a href="https://www.kaggle.com/datasets/cashncarry/fifaworldranking">FIFA rankings.</a> Both can be found on Kaggle and have the results of games until 2024–06–11. For the model, I used the results from 2019–08–01.</p><p>The ML Model performance could be improved a lot if we use advanced football data, like Expected Goals, and stats like Shots, Corners, and Free Kicks. The problem is that retrieving this kind of data for International Matches is quite hard.</p><h3><strong>Features Engineering</strong></h3><p>The development of the features was the same as I did in the 2022 World Cup project. I used almost the same code but created a new set of features that were based on the team’s goal-scoring and avoided weighted by the Rank Difference of teams involved:</p><ul><li>home_weight_goals &amp; away_weight_goals: the average of goals made by the team multiplied by the Rank Difference.</li><li>home_weight_points &amp; away_weight_points: the average of points made by the team multiplied by the Rank Difference.</li></ul><p>Also, I made the weighted version of goals in a moving average of 5 games, again by the Rank Difference.</p><p>The previous project, of 2022 WC, brought me some insights about features: in International matches, the FIFA Ranking is a good predictor. And the difference between the team’s ranking is better. With the current problem of predicting the number of goals, the features of team goals, and opponent suffered goals average would have good possibilities of being also good predictors. That’s why I decided to combine both.</p><h3><strong>Data Analysis</strong></h3><p>The next step is to analyse the data and select the features with predictive power to the model. The aim of the model now is to predict the number of goals, from home and away team, in separate models, so the analysis made in the WC 2022 prediction article can’t be used, but as I said, it gave me a clue: Rank Difference is a good predictor.</p><p>The first analysis I will do will be the linear regression plot between the possible features and the target (goals scored home/away). With this, we will be able to find any possible linear relationships</p><p>Since goals in a game is a continuous variable with a very limited set (the less a team can make in a game is 0, and it’s extremely rare for a team to score more than 6 goals in a game), I’ll also analyse how the number of goals affects the distribution of variables with a higher probability of having predictive power, such as team goals average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lx7CHf-PRA_oaDaaR-s4sw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z4xu00jYRGSTP12eVgCn6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QXll0R3cgSDXyx1u0zxL5Q.png" /><figcaption>Linear relation between the features and the target</figcaption></figure><p>The plot above shows the first analysis for the Home Team. As expected, none of the features had a clear linear relationship, but, rank difference and features weighted by the rank difference are the ones more visually affected. That’s why I’ll try to see how their distribution is being affected by the number of goals in a match.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-fS8F2e4wZUgOLzuiMVRjQ.png" /><figcaption>Distribution of possible features affected by the Home goals</figcaption></figure><p>Home average goals weighted by the rank difference clearly have the distribution affected by the number of goals, mainly when differentiating between 0, 1, 2, and 3 goals. This also happens with Away average suffered goals weighted by the rank difference, and the average of points made by home and away weighted by the rank difference. The moving average of 5 game versions of these features isn’t so affected by the number of goals.</p><p>This gives us a clue of what’s going to happen with away features. I’ll test then, the weighted features, with only the full average.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N8obggfSPRvm7phW5fKSUQ.png" /><figcaption>Distribution of possible features affected by the Away goals</figcaption></figure><p>The result is quite similar, but in the opposite direction, as expected. Since away teams with lower ranks than the home team are supposed to be stronger, when we have positive features in the away model the expectation is that the away team wins, and the opposite for the home team model.</p><h3>Machine Learning Models</h3><p>Now that we have the features, we’ll need to develop the two models, one to predict Home Goals and the other to predict Away Goals. I’ll test three models: Linear Regressor, Random Forest Regressor, and Gradient Boosting regressor. Since the features don’t have a clear linear relationship with the target, I’ll score the model with <a href="https://en.wikipedia.org/wiki/Mean_squared_error">Mean Squared Error (MSE)</a>, instead of an R2 Scorer, but, the main analysis to select the model will be seeing the distribution of predicted values and the residuals.</p><p>For both Home Goals and Away Goals, I selected the Random Forest model.</p><p>For the Home Team, I’ll show the analysis of the Linear Regression and Random Forest (the selected model), to explain why I selected the RF. First, let’s see the differences between the Actual vs Predicted values, for both models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*OeER8JtzJ4CJzfcNtASuNg.png" /><figcaption>Linear Regression difference between Actual and Predicted Values</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*Hc6JCZ7NO5T6NXmgeCj_mQ.png" /><figcaption>Random Forest difference between Actual and Predicted Values</figcaption></figure><p>If we see both plots, we see a similar pattern of error. But, also, we can see where Linear Regression fails in this problem. As I said, even with the number of goals being a continuous variable, its set is very limited. We can’t have less than 0 goals in a match, as the Linear Regression predicted sometimes, because Linear Regression models can <strong>extrapolate </strong>their predictions over and under the boundaries seen in the training, while tree-based models can’t.</p><p>This is often considered a problem in tree-based models, but here, it’s a huge quality compared to the Linear Regression model.</p><p>Of course, we can manually set lower than 0 values predicted by the Linear Regression to 0, but this is only worthwhile if the model performs too better than the Random Forest. Let’s see the residuals to analyse that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*KwmdsXXi6rrjzrIAIuQBcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*fqPqHpcbvK82N9OH2bXHOQ.png" /><figcaption>Linear Regression (left) and Random Forest (right) distribution of residuals</figcaption></figure><p>The residuals of a regression model are the difference between the predicted value and the actual value. We can see above that Random Forest underestimates home team goals a little bit more than Linear Regression, but it isn’t a big difference to justify using Linear Regression with a fix for negative predictions. That’s why I selected the Random Forest.</p><p>I followed a similar analysis in the Away Goals model and selected the Random Forest again. Between RF and Gradient Boosting, the results are very similar. I chose to continue with RF because I’m using a small database, which tends to overfit with more complex models.</p><h3><strong>Poisson Model</strong></h3><p>Now that I have the models to predict the λ parameter for home and away team distributions, I can calculate the probabilities of Home Win, Draw, and Away Win.</p><p>To do that, I first calculate the Poisson Probability for 0 to 10 goals. Let’s see the example of Germany and Scotland, the first game of the UEFA Euro:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*OQkmqQ_JfzesYAJgQJR59Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*7msuuoi6TPdAvn5UYSuhnA.png" /><figcaption>Germany and Scotland Poisson distributions</figcaption></figure><p>Now that we have the probabilities of each team scoring 0 to 10 goals, we can calculate the probabilities of each exact result, which is shown in the table below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*OFWAkprA3uJghS4T4FvPIg.png" /><figcaption>Scoring probabilities</figcaption></figure><p>In red, we see the probabilities of scenarios where Scotland wins. In green, are the ones where Germany wins. And in yellow, the draws. To have the probability of Germany winning, draw, and Scotland winning, we sum each part of the matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*WiTItXQT8wXYmG6ZCgckFA.png" /><figcaption>The probability of each team winning</figcaption></figure><h3><strong>Simulation</strong></h3><p>With all the models ready, we can go to the fun part. To simulate the games, we predict the expected value of goals for each matchup in the group phase, but, we have a problem: the model clearly underestimates a lot of the draws. So, I decided to give compensation to draws, in order to adjust that: removing 5% of each team probability and adding this to the draw probability.</p><p>The results of the simulated games are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*aQrXU_KSbp4Us-UCmHHzmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/1*G7nMVB0rADg7GYMXkXLikA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*vBFU5MnXRlNQlJpjXCvkvg.png" /><figcaption>All results of group phase games listed</figcaption></figure><p>After the simulation of the group stage, I calculated how the groups turned out. That’s the complete table, with all groups:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*I3eT27PnyS-g9G_LF11LoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*Smhtp6B_20kLzVHalgsNyg.png" /><figcaption>All groups</figcaption></figure><p>I think the biggest surprise is France losing their game against the Netherlands and Italy, the title holders, staying behind Croatia. As we can see above, I had already calculated the best third-place teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/317/1*J1bw-_MZ7LOORPou4_OSsg.png" /><figcaption>Best third-place teams</figcaption></figure><p>After that, I need to simulate the knockout stage. The UEFA Euro has a very strange match combinations that you can find <a href="https://en.wikipedia.org/wiki/UEFA_Euro_2024_knockout_stage">here</a> and was the base for my code to draw the matches. The result is shown below, in the same chart I did for the WC 2022 simulation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i4nbjXkYv9e4em_SnhMNBw.png" /><figcaption>Knockout stage simulation</figcaption></figure><p>We can see that France is the predicted winner, which I think is very realistic. Belgium was the runner-up, and I think this is very surprising, especially beating England in the semi-final, in a very tight game.</p><h3><strong>Conclusion</strong></h3><p>Again, the idea of the project was to use my knowledge of Data Science and ML to predict one of the things I like the most: football. But, at this time, I also wanted to fix some flaws that I think my first model had, as an example, the WC 2022 model didn’t predict draws!</p><p>I think this goal was achieved. This model is more science-based and reflects a lot of what the state of the art in Football Prediction is. Also, the model can be used for more things, for example, getting a probability of more than 3 goals happening in a match.</p><p>If you want to see the code in detail, please check the <a href="https://github.com/sslp23/eurocup_sim/tree/main">GitHub Repo</a>. If you want to reach me, that’s my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><h4>A Message from AI Mind</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*5Wm7sOfTpe5DEbhg.gif" /></figure><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://pub.aimind.so/">AI Mind Publication</a></li><li>🧠 Improve your <a href="https://www.aimind.so/prompt-generator?utm_source=pub&amp;utm_medium=message">AI prompts effortlessly and FREE</a></li><li><strong>🧰 Discover </strong><a href="https://www.aimind.so/?utm_source=pub&amp;utm_medium=message"><strong>Intuitive AI Tools</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7b22bacc06e" width="1" height="1" alt=""><hr><p><a href="https://pub.aimind.so/a-machine-learning-poisson-model-to-predict-uefa-euro-2024-d7b22bacc06e">A Machine Learning — Poisson model to predict UEFA Euro 2024</a> was originally published in <a href="https://pub.aimind.so/">AI Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating an Expected Points (xP) Model for Football Teams]]></title>
            <link>https://pub.aimind.so/creating-an-expected-points-xp-model-for-football-teams-95b41261d1ed?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/95b41261d1ed</guid>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[football]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 15:58:27 GMT</pubDate>
            <atom:updated>2023-11-01T20:00:52.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Creating an Expected Points (xP) Model for Football Matches</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ErRyFpCh72W6Puvn" /><figcaption>Photo by <a href="https://unsplash.com/@fancycrave?utm_source=medium&amp;utm_medium=referral">Fancy Crave</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Since I started my profile to share statistical and data insights about football on <a href="https://twitter.com/sergiopessoa23">X/Twitter</a>, I’m following up on the Expected Points (xP) table of the Brazilian National Championship, in season 2023. The idea of Expected Points is to add context to the teams’ points as well as Expected Goals for teams’ shots.</p><p>Like Expected Goals, which we can describe as the probability of a shot becoming a goal, Expected Points can be described as the probability of each team winning the match, <strong>based on the goal chances of each other</strong>. With these probabilities, we can express how many points the team should get from this match, and calculating for all matches of the season we can create a “Justice” Table, to see which teams are overperforming and underperforming.</p><p>The Model is quite simple, for one match we need:</p><ul><li>Shots of each team and its respective xG.</li><li>Simulate the game N times, and for each team, we get its respective number of wins, draws, and losses.</li><li>With these numbers, we can extract the probabilities of win, loss, and draw by dividing by the Number of Simulations, and then we can get the Expected Points (xP) of the team by multiplying win probability by 3 plus draw probability.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*8_o2Vc8YqRNu51tistNppA.png" /><figcaption>xP calculation</figcaption></figure><p>With the values for each game, we can build an Expected Points ranking that would be our “Justice” Table.</p><h3>Data</h3><p>What we need to calculate xP for one game is simply all the shots made by each team and their respective xG value. We can get this data from <a href="https://fbref.com/en/">FBREF</a>, for some leagues, like the Top 5 European Leagues or the Brazilian 1st Division.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QrC4gUsYwV9dNbJcWG0e-w.png" /><figcaption>List of shots from FBREF, Palmeiras vs. Goiás game.</figcaption></figure><p>To scrape this data, I built a code in Python that can be seen in my <a href="https://github.com/sslp23/points_tracker">GitHub</a>.</p><h3>Simulating the Match</h3><p>Once we have shots and their respective xG value, we can simulate if a shot ended up being a goal. If we see xG as the probability of a shot being a goal, it becomes easier to understand:</p><ul><li>For each shot of the team, we generate a random number, and if the xG value of the shot is higher than this number, we assign a goal for the team.</li><li>We do that for both teams and then compare which team ended up with more goals.</li></ul><p>Below I show the function that I created to do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*GwaLMCjbMQ0kOB8vLD8oTA.png" /><figcaption>Code to simulate one specific game</figcaption></figure><p>With that, we have a unique simulation of any game. But what we need is probabilities. How to extract probability from this? The answer is simulating a lot of times. This comes from the <strong>Law of Large Numbers</strong>, which states that the sample average of large samples comes closer to the true population average. In other terms, the more we simulate the game of Team A vs. Team B, the closer to having the true average of Team A wins, Team B wins and Draws we are. This average we will assume as Team A’s probability of winning, Team B&#39;s probability of winning, and draw probability.</p><p>To do this simulation, I developed this function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*jjwLW1wbYHqy1iPCM4ruIg.png" /><figcaption>Code to simulate the game N times</figcaption></figure><p>In the code above we can see that, at first, I did the simulation of a specific match N times, and then I got the number of Home Wins, Away Wins, and Draws. With these numbers, I applied the xP equation and got the xP value for home and away from the game of interest.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*2K31URCAqujobrOP2io47Q.png" /><figcaption>Palmeiras vs. Goiás Expected Points</figcaption></figure><p>For the Palmeiras vs. Goiás match, from above, we are going to have Palmeiras with 1.842 xP and Goiás with 0.804 xP.</p><h3>Creating the “Justice Table”</h3><p>With the code for finding xP of one game done, becomes very easy to simulate for all games. Iterating game by game we achieve the following result for the Brazilian National Championship, week 24:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wzHKYlwIO3tJ8jL16USqpg.png" /><figcaption>Justice Table for Brazilian Championship</figcaption></figure><p>In the chart, I compare the total points of the team, the home points, the away points, and the expected points. The xP in this analysis can be seen as a KPI of the team’s performance. For example, Vasco da Gama stayed at the bottom of the table in the championship for months, even with a good xP value. As expected, and shown below, their points average crossed their xP average, and the team went out of the relegation zone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e6bqQsG4tmz65Dn17g6D4w.png" /><figcaption>Vasco 5 Games SMA — xP and Points</figcaption></figure><p>Another visualization I like is seeing the xP of a given week, to see the upsets that happened.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2az0u7cmej6vllKs8xakRA.png" /><figcaption>Week 24 xP — Brazilian National Championship</figcaption></figure><p>This is a good way to compare if the winners of the match were the ones with more attacking production. For example, in the match São Paulo vs. Fortaleza, the most expected result for both teams was a draw or even a win for São Paulo, but Fortaleza won the match. On the other hand, Vasco achieved an uncontested victory against Coritiba, with absolute dominance in the game, and this is shown by the xP.</p><h3>Conclusion</h3><p>The calculation of Expected Points is a good way to keep tracking the Team’s performance during the league. It uses the chances created by the team to calculate how many points they deserve in the game. With these values, we can see if the team is over or underperforming in the championship, which could help us to make predictions.</p><p>Also, It was a very good way to test my statistics skills. Using the xG values, which is a lot used in current Football Analysis, and applying statistical concepts to achieve a new stat. It was a good opportunity to develop routines to get football data from the best sources in automatical ways too.</p><p>If want to see the code of the project in detail, take a look at the project’s <a href="https://github.com/sslp23/points_tracker">GitHub Repo</a>. If you want to reach me, take a look at my <a href="https://twitter.com/sergiopessoa23">Twitter/X</a> account or my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><h4>A Message from AI Mind</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*5Wm7sOfTpe5DEbhg.gif" /></figure><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://pub.aimind.so/">AI Mind Publication</a></li><li>🧠 Improve your <a href="https://www.aimind.so/prompt-generator?utm_source=pub&amp;utm_medium=message">AI prompts effortlessly and FREE</a></li><li><strong>🧰 Discover </strong><a href="https://www.aimind.so/?utm_source=pub&amp;utm_medium=message"><strong>Intuitive AI Tools</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95b41261d1ed" width="1" height="1" alt=""><hr><p><a href="https://pub.aimind.so/creating-an-expected-points-xp-model-for-football-teams-95b41261d1ed">Creating an Expected Points (xP) Model for Football Teams</a> was originally published in <a href="https://pub.aimind.so/">AI Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a data-driven NFL Fantasy Draft]]></title>
            <link>https://pub.aimind.so/making-a-data-driven-nfl-fantasy-draft-ad8bafd044c3?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad8bafd044c3</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Wed, 23 Aug 2023 20:41:14 GMT</pubDate>
            <atom:updated>2023-08-25T15:53:09.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*03AcM-kHP725ilfK" /><figcaption>Photo by <a href="https://unsplash.com/@project290?utm_source=medium&amp;utm_medium=referral">Project 290</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>September is coming and the NFL fans are excited about the arrival of another season. Also, many Fantasy players must be anxiously awaiting the long-awaited arrival of the Fantasy Draft. I was one of them, and with little time to follow the news of the busy offseason, I decided to use my Data Science skills to optimize my choices.</p><p>My idea was to create a better predictor of performance than the most used (such as FantasyPros predictor) using Machine Learning, and then use statistics to predict whether picking a player in a given round is a good option or not, based on his points’ projection.</p><p>So, the project pipeline was:</p><ul><li>Get data from NFL players’ past seasons (2018–2022, at least).</li><li>Process this data to create relevant features for each position.</li><li>Create an ML model for each position (QB, RB, WR, and TE).</li><li>Calculate the probability of a player being selected in each round and evaluate if it’s a good pick based on his Projected Points.</li></ul><p>All the code of the project is on the <a href="https://github.com/sslp23/ff_optimizer/tree/main">GitHub Repo</a>, if you want to follow in details the implementation.</p><h3>Getting and Processing Data</h3><p>My first step was to get the data and process to create features for the ML model. I decided to get all the data from the <a href="https://fantasypros.com/">FantasyPros website</a>. They are probably the most famous website and provided everything I needed:</p><ul><li>Average Draft Position (ADP) of players in the following season and the past seasons, to create the model and to predict if it’s a good pick.</li><li>Stats for the players for each position, to create the model.</li><li>A points projection for the past season, to be used as a comparison to test my model.</li></ul><p>Since they provided ADP data from season 2018 until the last one, 2022, I got these as my seasons to train the model.</p><p>After getting the data, the next step would be processing it. My idea was to use as a target the Points Per Game (PPG) value, so I weighted all the columns by the games played in the season for each player. With that, I created for each season, from 2018 to 2022, the following features:</p><ul><li>Simple Moving Average (SMA) of each stat for the past 3 seasons.</li><li>Exponential Moving Average (EMA) of each stat for the past 3 seasons.</li><li>YDS/ATT, TD/ATT for rushing stats.</li><li>YDS/REC, YDS/TGT, REC/TGT, and TD/TGT for receiving stats.</li><li>ADP and how many years of career.</li><li>SMA and EMA of Fantasy Points for each player.</li></ul><p>The goal was to use the above features as a baseline, see if they had predictive power, and create new features for each model specifically.</p><h3>The Model</h3><p>For the modeling step, I did a standardized analysis based on seeing the correlation between the baseline features I created and the target, and the correlation between the weighted version of the baseline features by the ADP, EMA Fantasy Points, and SMA Fantasy Points. I can summarise the results by:</p><ul><li>Weighing features by past Fantasy Points were effective for all positions.</li><li>Weighing features by season ADP was effective only for the WR position.</li></ul><p>The idea of weighing the features came to me because the stats of ADP and SMA/EMA of past Fantasy Points were significantly correlated with the target and the pure stats of the player weren’t. With the weighing, I could see a clear improvement in feature relevance for the stats. Below is the difference for some WR stats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*jXHXEgJjr02TQYpqmlsmpg.png" /><figcaption>Feature Correlation between pure stats and the target, for WR</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*qbqU4I776zHtqu1IA5earw.png" /><figcaption>Feature Correlation between stats weighed by past Fantasy Points and the target, for WR</figcaption></figure><p>With the features done, I started to develop the models. For all positions the Random Forest models were the best, changing only the parameters, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yuSVJ6vwuF7aR-2kMzuJ3Q.png" /><figcaption>Models parameters</figcaption></figure><p>And, to assess model performance I compared the results for the 2022 season with the projected of FantasyPros. The result for the RB position can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7Eqke3wCbYNvI_5oVryzA.png" /><figcaption>Comparison between FantasyPros and Model projections for the 2022 Season.</figcaption></figure><p>The comparison shows that my model performed better, with lower error and a higher R2 Score, for the RB position. This is what we wanted to use as a baseline for our draft.</p><p>The only remaining step to predict the performance of the players in the 2023 season was dealing with the rookies. Since they are in their first year in the league, we can’t calculate EMAs and SMAs for them. So, my idea was to replace their past performance with an average of the players closest to their ADP in the last 5 seasons. For example, Bijan Robinson&#39;s ADP is 8.7, so I averaged the stats of the closest to 8.7 RB for the last 5 seasons to get an estimate of his performance. There isn’t a consensus on how to deal with rookies and this is one of the biggest challenges in NFL predictions.</p><p>After, I predicted the expected Points Per Game for the 2023 season and created a board with the projection for each player. The result is described in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*BmH1WUOf0cHN2qxmgs_Sgw.png" /><figcaption>Board with predictions from the model</figcaption></figure><p>The column AVG is the average ADP that the player currently has and the column STD is the standard deviation of ADP that the player has. Both are provided by FantasyPros and are used to calculate the probability of a player being drafted in each round.</p><h3>Draft Analysis</h3><p>To get an optimal draft we need to balance two things:</p><ul><li>Get the player with the highest projected points.</li><li>Avoid getting players that will be available in the following round.</li></ul><p>The first one is pretty obvious since we want to maximize the points that the team will make. The second is quite straightforward to understand too: even if he is a good player, if his chance of being available in the next round is high, it’s better to pick another player that is as good as but won’t be available in the future.</p><p>To target these needs I’ll work with two stats: VOR and Next Round Probability.</p><p><strong>What’s VOR? </strong>Probably is the most used statistic to evaluate players in American leagues nowadays. It’s quite simple to understand: for each position, in this case, QB, TE, RB, and WR, we’ll have a player called “replacement player”, which can be chosen in many ways. I’ll choose my replacement players using the logic of the ADP threshold. It is, I’ll determine a threshold of ADP, and the closest player above this threshold by each position will be assigned as the replacement player. With the replacement player chosen, the calculation of the VOR is very simple. It’s the difference between Player Projected Points and Replacement Player Projected Points. I used as threshold ADP 100, and these are the Replacement Players&#39; projected points:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*Q0yrWMD1Eq2T5GnA2uoqSg.png" /></figure><p>The positive thing about VOR is that it helps to capture the values of each position. The average expected PPG of a QB is obviously higher than an RB, but his replacement expected PPG is also higher, for example. That’s why is more common to get RBs over QBs, in Fantasy Drafts.</p><p><strong>Next Round Probability </strong>calculation can be done using the cumulative normal distribution. This is easy to understand when we think that the Fantasy Draft is a probability distribution with each player as a point, having its average and standard deviation. That way, if we take the cumulative density function of the Draft distribution for a given player, we’ll have the probability of the player being picked before the target position, so just subtract 1 from this probability and we’ll have the probability of the player being available in the target position, which will be the next round position.</p><p>With these two statistics, I can create what I called as <strong>VOR Loss</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*oY0noppzpwMZSlChK9oZpg.png" /><figcaption>VOR Loss Calculation</figcaption></figure><p>VOR Loss is basically how much of VOR I’m losing if I do not select the player in this round. It calculates the average VOR of the top 3 players in this position with more than 50% of chance of being available in the next round. The higher the VOR Loss of a player in a given round, the higher his value in this round. So, our last step is to create a framework to simulate the draft that calculates the VOR Loss round-by-round and keeps on track of how we are doing.</p><p>The logic is to receive as input the draft position, calculate VOR Loss, and display two tables: first containing players with more than a 30% chance of being available in the current round and second with the player with ADP inside this round. Below I show an example of these two tables using Position #5 as input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEHlk5v_AvprCCSvgoKzEg.png" /><figcaption>First Table: Top Players to pick by VOR Loss.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CtnkW8-TQOB6IDhmR8nW7g.png" /><figcaption>Second Table: Players with ADP between First Round and their VOR Loss.</figcaption></figure><p>The final task I did was the creation of a tracker that received the selected player as the input and stored his information and the accumulated VOR Loss for each position when you select him in this round. The result is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZddAmv4Ckw75_V64w8eRA.png" /><figcaption>Draft tracker</figcaption></figure><h3>Conclusion</h3><p>I can say that the project results were very satisfying. I had two goals with this, the first was to train my DS skills and the second was to buy time avoiding having to read multiple news and follow all updates of the offseason, and I think that I succeeded in both.</p><p>With the scraper of FantasyPros, I can track very easily all the changes in the draft logic, and also use the stats as a baseline for my Draft Framework. Also, I’m satisfied with the ML model I created. I wasn’t used to working with regression problems, so it was a very good project to train it.</p><p>As improvements, I think that we could target three things that would have a positive impact, but would increase a lot the difficulty of the project: automate the Draft Framework with live information from your draft website, improve the ML model with more deep stats, and create a predictor of NFL performance for rookies based on their draft and college stats. These are changes that take a long time to make but would improve a lot the complexity of the project.</p><p>Finally, if you want to see the code of the project in detail, this is the <a href="https://github.com/sslp23/ff_optimizer/tree/main">GitHub Repo</a>. If you want to reach me, this is my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><h4>A Message from AI Mind</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/0*5Wm7sOfTpe5DEbhg.gif" /></figure><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://pub.aimind.so/">AI Mind Publication</a></li><li>🧠 Improve your <a href="https://www.aimind.so/prompt-generator?utm_source=pub&amp;utm_medium=message">AI prompts effortlessly and FREE</a></li><li><strong>🧰 Discover </strong><a href="https://www.aimind.so/?utm_source=pub&amp;utm_medium=message"><strong>Intuitive AI Tools</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad8bafd044c3" width="1" height="1" alt=""><hr><p><a href="https://pub.aimind.so/making-a-data-driven-nfl-fantasy-draft-ad8bafd044c3">Making a data-driven NFL Fantasy Draft</a> was originally published in <a href="https://pub.aimind.so/">AI Mind</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using data to scout football players]]></title>
            <link>https://medium.com/latinxinai/using-data-to-scout-football-players-bda765ec3765?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bda765ec3765</guid>
            <category><![CDATA[latinxinai]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[expected-goals]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 15:44:32 GMT</pubDate>
            <atom:updated>2023-03-16T02:31:54.260Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zK-6izrDwzOFSJBC" /><figcaption>Photo by <a href="https://unsplash.com/@jannesglas?utm_source=medium&amp;utm_medium=referral">Jannes Glas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In 2017, Manchester City made a big signing in the winter transfer window: the Brazilian forward Gabriel Jesus. The striker was the best player in Brazilian National Championship in 2016, and the top scorer of the winning team, Palmeiras. Soon in the 2016–17 season, Gabriel Jesus started to show his good skills: made 7 goals and 4 assists, playing 8 games as a starter. In the next season, he made 13 goals and 4 assists and helped Manchester City to win their 5th Premier League title.</p><p>After six seasons playing for City, Gabriel was sold to Arsenal for £45 million, giving a profit of more than £15 million to the Manchester club, and after winning 4 Premier League titles. We can say, with no doubt, that he was a very good signing.</p><p>Given that background, we can question ourselves: how we can find a player such as Gabriel Jesus playing in another league? Data can help us. My idea in this project is to use the player stats from the 2017–18 Premier League season and create an algorithm to find similar players to Gabriel Jesus in the Spanish La Liga, of the same season.</p><p>We are going to gather stats that measure the performance of a striker, and, with that, calculate the Euclidean Distance of Gabriel Jesus’ stats with La Liga’s strikers&#39; stats. After that, we can compare the player radars’ of both players and see if they are similar.</p><h4>Data Source</h4><p>Football has a big variety of stats nowadays, and some of them are very hard to collect. That’s why I’ll use the free data of WyScout, one of the biggest companies in football data nowadays. On their <a href="https://footballdata.wyscout.com/download-samples/">website</a>, there is free data from the 5 major Europe leagues from the season 2017–18. The data consists in:</p><ul><li>Events are the data of everything that happened in a match during the 90 minutes and extra time.</li><li>Matches, the file with the information of everything related to the match such as home team, away team, and formations.</li><li>Players, the file that shows information such as the player&#39;s first name, second name, and role.</li></ul><p>With that, I can build a dataset of all match events with the team’s names and players’ names, which is needed to find the stats of the players.</p><h4>Stats</h4><p>The first challenge with the data is creating stats that capture with accuracy the quality of a player. As stated by <a href="https://soccermatics.readthedocs.io/en/latest/index.html">David Sumpter, from Soccermatics</a>, we need metrics that have <strong>context </strong>and<strong> comparison</strong>.<strong> </strong>The context means that we need to express in the stats things that are important to the game. As an example, we can’t say that a player with a high % of pass completion is a good passer: we don’t know how the passes are made. But, with the context of passes to the final third of the field, we have so much more information to say if he is a good passer or not.</p><p>Comparison is another thing that we need to have in our metric. We can’t simply analyse Gabriel Jesus&#39; stats alone, for example. We need to see if the metrics that he made are good in comparison with other players from the same league. One way to see that is the use of percentiles.</p><p>Also, we need to normalise all these metrics by the number of minutes each player played. To do that, we multiply the season stat by 90 minutes and divide it by the number of minutes played in the season. This means that we rescale the data as if the player had played all the games and then divide it by the number of games that he played.</p><p>Based on the book Soccermatics, I decided to use these stats:</p><ul><li>Passes into Final Third of the Field;</li><li>Receptions inside the Final Third of The Field;</li><li>Attacking duels won;</li><li>Non-penalty expected goals;</li><li>Major stats (goals, assists, key passes).</li></ul><p>The first stat, assists and key passes are used to see how much impact the player is doing with his passes. Passes into the final third are calculated by me, and I considered only completed passes. Key passes are a stat made by wyscout and given to us by their data, and assists are the number of passes previous to the goal that a player made in the season.</p><p>Receptions inside the final third are a good metric to analyse the positioning of the forward. Attacking duels are good to see if the player is a good presser. These stats were also calculated by me.</p><p>Non—penalty expected goals are one of the most important football stats nowadays. In order to find the expected goals, I created a Machine Learning model using logistic regression and fit it into every shot that happened in the Premier League 2017–18. I tested the model with 4 combinations of features:</p><ul><li>Angle;</li><li>Distance;</li><li>Distance and Angle;</li><li>Distance**2, Distance * Angle, Angle**2;</li></ul><p>And it resulted in the following ROC-AUC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*ccyM0g1BPDwrXF-E8ItEFw.png" /></figure><p>So, I decided to use the distance and angle model, which is simpler than the polynomial but with the same AUC score. You can see the code with details in my <a href="https://github.com/sslp23/football_player_scout/blob/main/expected%20goals.ipynb">GitHub</a> and see how to create an expected goals model <a href="https://soccermatics.readthedocs.io/en/latest/lesson2/introducingExpectedGoals.html">here</a>.</p><p>The last stat is very self-explanatory for measuring the striker&#39;s quality, which is goals.</p><p>All these stats are normalised by the minutes played for each player. I created a summary for the English and Spanish league, containing the stats for each league for the season 2017–18.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*_x_ztvaKlR8v4nC4jYkoZg.png" /><figcaption>Gabriel Jesus stats</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*D7_7icJc47X4gMWZ9K42ew.png" /><figcaption>Premier League 2017–18 Summary</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*Dl_5ZCtJVk17R46Q_Q5Cbg.png" /><figcaption>La Liga 2017–18 Summary</figcaption></figure><p>In order to visualize a player’s performance, I used the Player Radars. They are graphs that show the values of each variable of interest and also we can add the percentile in which his value belongs in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*i-lALqjsJF3jhG0C1CiL9Q.png" /><figcaption>Gabriel Jesus 2017–18 Player Radar</figcaption></figure><p>Above we can see Jesus’ Player Radar for the 2017–18 season. The dotted lines are the percentile lines. We can see that Jesus is one of the bests in goals, non-penalty xG, and very good in passes and receptions in the final 3rd. Also, he has a decent performance giving key passes.</p><h4>Player Scout</h4><p>To scout a player similar to Gabriel Jesus in La Liga, we need to use some similarity algorithm. I thought of the Cosine Score or the Inverse Euclidean Distance, which was my choice because gave better results after testing both. The formula to use the inverse of euclidean distance is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*hM2OJwRhh-Mn3JsUvQKMZw.png" /><figcaption>Euclidean Distance</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/114/1*DUZVZ5qo9sPks8K_9X5bCg.png" /><figcaption>Inverse Euclidean Distance</figcaption></figure><p>After calculating that for all the La Liga strikers, I standardized the values using the maximum and the minimum value of the Inverse Euclidean Distance score to get the range of similarity score between 0% and 100%. The most similar players are shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*0p4zhHhJntRQ1crW3LADMw.png" /><figcaption>Most Similar Players to Gabriel Jesus in La Liga 2017/18</figcaption></figure><p>As you can see, the top similar player was Wissam Ben Yedder, followed by Santi Mina and Rodrigo. Let’s take a more deep look at Ben Yedder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*UduQCOHvUUFm35nrf5n9AQ.png" /><figcaption>W. Ben Yedder 2017–18 Player Radar</figcaption></figure><p>As Gabriel Jesus, W. Ben Yedder is one of the top players in non-penalty xG in his league. Also, he’s very good in goals and passes to the final 3rd, has a similar performance with Gabriel Jesus in key passes, is better in assists, and is worse in receptions in the final 3rd. They both are at the bottom of the league in attacking duels. We can see the comparison below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*50E96ela2OKVAJWgwH4kTw.png" /><figcaption>Gabriel Jesus and W. Ben Yedder comparison</figcaption></figure><p>The graph above shows what I said, they are players with similar performance with differences in some stats.</p><p>This season, Ben Yedder was a Sevilla player, he played 3 years in the club and scored 70 goals, a great performance. After that, Monaco signed him and he become the top scorer in the 2019–20 Ligue 1, with 18 goals, the same number as Mbappé and more than Neymar, proving to be a great signing.</p><h4>Conclusion</h4><p>With the presented project, we can say that player stats are a very good indicator to find good players in another league. One way to do that is by using the stats of a player who is performing well in the league and trying to find a similar one in another league, as done here using Euclidean Distance.</p><p>Here, we tried to find a similar player to Gabriel Jesus, a very good performing striker from Premier League and found W. Ben Yedder, who was a very good player hidden at minor clubs in other leagues. This shows that he probably would be a great signing for a Premier League club, as he was to Monaco two years later.</p><p>Also, the project was very good to study some of the techniques to do football analysis using stats, such as modeling an Expected Goals algorithm with Machine Learning and creating Player Radars.</p><p>In case you can see the code in detail, you can see my <a href="https://github.com/sslp23/football_player_scout/tree/main">GitHub</a>. And if you want to reach me, that’s my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*QSnwD1dB3tDo5H9X" /><figcaption>LatinX in AI (LXAI) logo</figcaption></figure><p><strong>Do you identify as Latinx and are working in artificial intelligence or know someone who is Latinx and is working in artificial intelligence?</strong></p><ul><li>Get listed on our directory and become a member of our member’s forum:<a href="https://lxai.app/"> https://lxai.app/</a></li><li>Become a writer for the LatinX in AI Publication:<a href="http://bit.ly/LXAI-Volunteer"> http://bit.ly/LXAI-Volunteer</a></li><li>Learn more on our website:<a href="http://www.latinxinai.org/"> http://www.latinxinai.org/</a></li></ul><p><strong>Don’t forget to hit the 👏 below to help support our community — it means a lot!</strong></p><p><strong>Thank you :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bda765ec3765" width="1" height="1" alt=""><hr><p><a href="https://medium.com/latinxinai/using-data-to-scout-football-players-bda765ec3765">Using data to scout football players</a> was originally published in <a href="https://medium.com/latinxinai">LatinXinAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Predicting FIFA 2022 World Cup with Machine Learning]]></title>
            <link>https://medium.com/latinxinai/predicting-fifa-2022-world-cup-with-machine-learning-640f1d2d7e98?source=rss-a9bd5bd0981c------2</link>
            <guid isPermaLink="false">https://medium.com/p/640f1d2d7e98</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sergio Pessoa]]></dc:creator>
            <pubDate>Fri, 18 Nov 2022 21:57:03 GMT</pubDate>
            <atom:updated>2024-06-13T21:15:44.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CucQdXxv3djph2Hn9VfTEA.jpeg" /><figcaption>@<a href="https://unsplash.com/@akeenster">akeenster</a></figcaption></figure><p>With the approach of FIFA 2022 World Cup, the interest and discussions about which team is going to win the championship increase. Thus, I decided to test my Data Science and Machine Learning skills to develop a model analyzing historical data to simulate all games from FIFA 2022 World Cup.</p><h4>Data Source</h4><p>In order to build a Machine Learning model, we need the data from the teams. First, we need something that tells the performance of the teams, which can be extracted from previous games. Also, I decided to use the FIFA Rankings in the construction of the features. They will be helpful to quantify the quality of the opponent that the team faced in a game. Both data can be found on Kaggle: <a href="https://www.kaggle.com/datasets/martj42/international-football-results-from-1872-to-2017">past games</a> and <a href="https://www.kaggle.com/datasets/cashncarry/fifaworldranking">FIFA rankings.</a></p><h4>Dataset building</h4><p>Which features can bring impact to decide the winner of a football game? This question has a very open answer. From the selected players to the temperature at the stadium during the day, everything can make an impact on the outcome. Then, I chose to build a dataset only with the past stats from each team involved in the game, prioritizing the quantifiable stats that can be gathered in a simple way, such as goals made, mean ranking faced, points won, and others that will be detailed. Those data can be found in the join of both datasets that I’ve talked about in the last section.</p><p>Also, only the performance at the 2022 World Cup cycle will be analyzed. The idea is to take into account only the variation of performance in preparation for the World Cup.</p><pre>import pandas as pd<br>import re<br>df =  pd.read_csv(&quot;games/results.csv&quot;) #games between national teams<br>df[&quot;date&quot;] = pd.to_datetime(df[&quot;date&quot;])<br>df = df[(df[&quot;date&quot;] &gt;= &quot;2018-8-1&quot;)].reset_index(drop=True) #games at the 2022 wc cycle<br>df_wc = df #pre-wc outcomes<br><br>rank = pd.read_csv(&quot;fifa_ranking-2022-10-06.csv&quot;) #rankings<br>rank[&quot;rank_date&quot;] = pd.to_datetime(rank[&quot;rank_date&quot;]) <br>rank = rank[(rank[&quot;rank_date&quot;] &gt;= &quot;2018-8-1&quot;)].reset_index(drop=True) #selecting games from the 2022 wc cycle<br>rank[&quot;country_full&quot;] = rank[&quot;country_full&quot;].str.replace(&quot;IR Iran&quot;, &quot;Iran&quot;).str.replace(&quot;Korea Republic&quot;, &quot;South Korea&quot;).str.replace(&quot;USA&quot;, &quot;United States&quot;) #ajustando nomes de algumas seleções<br>rank = rank.set_index([&#39;rank_date&#39;]).groupby([&#39;country_full&#39;], group_keys=False).resample(&#39;D&#39;).first().fillna(method=&#39;ffill&#39;).reset_index()<br>rank_wc = rank #dataframe with rankings<br><br>#Making the merge<br>df_wc_ranked = df_wc.merge(rank[[&quot;country_full&quot;, &quot;total_points&quot;, &quot;previous_points&quot;, &quot;rank&quot;, &quot;rank_change&quot;, &quot;rank_date&quot;]], left_on=[&quot;date&quot;, &quot;home_team&quot;], right_on=[&quot;rank_date&quot;, &quot;country_full&quot;]).drop([&quot;rank_date&quot;, &quot;country_full&quot;], axis=1)<br>df_wc_ranked = df_wc_ranked.merge(rank[[&quot;country_full&quot;, &quot;total_points&quot;, &quot;previous_points&quot;, &quot;rank&quot;, &quot;rank_change&quot;, &quot;rank_date&quot;]], left_on=[&quot;date&quot;, &quot;away_team&quot;], right_on=[&quot;rank_date&quot;, &quot;country_full&quot;], suffixes=(&quot;_home&quot;, &quot;_away&quot;)).drop([&quot;rank_date&quot;, &quot;country_full&quot;], axis=1)</pre><p>Above is the code to create the wanted dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_dMor-voUdNb3dZZl0CRw.png" /><figcaption>View of the database</figcaption></figure><p>The dataset is ready, as you can see above, and there is more information about the away team. It’s important to remember that the majority of games between national teams are played on neutral venue, but I’ll use the names “home team” and “away team” to simplify the way in which I’ll talk about the teams involved.</p><h4>Features Development</h4><p>Now, I need a set of candidate features. With them I can make an analysis that will indicate if the feature has predictive power or not, to understand if I need to keep, remove, or modify the feature. The features I calculated as candidates were:</p><ul><li>Goals average at World Cup cycle and in the last 5 games.</li><li>Suffered goals average at World Cup cycle and in the last 5 games.</li><li>Difference in FIFA ranking positions between each team.</li><li>FIFA ranking that each team faced average at World Cup cycle games and in the last 5 games.</li><li>Increment in points in FIFA Ranking from the first game of the cycle and now.</li><li>Increment in points in FIFA Ranking 5 games ago and now.</li><li>Game points average won at World Cup cycle and in the last 5 games.</li><li>Game points average won weighted by ranking position faced at World Cup cycle and in the last 5 games.</li><li>Categorical variable telling if the game was a friendly or not.</li></ul><p>The first two features are used to quantify the offensive power and defensive power of a team. The difference between FIFA ranking position in the match is used to quantify the difference between both teams’ strengths as calculated by FIFA. Ranking faced average is used to put in analysis the strengths of opponents that a team faced.</p><p>The increment in FIFA ranking points was calculated to analyze the team quality increment during the World Cup cycle and in the last 5 games.</p><p>The game points average the team won is to purely quantify the team’s performance, while the weighted average of game points a team won is weighted by the opponent’s ranking position that the team faced, in order to analyze if the performance of the team is high due to low-level opponents.</p><p>To build features based on FIFA rankings, there are two choices: use FIFA ranking points, or use FIFA ranking position. I opted to use the ranking position in all features except the increment in ranking. I didn’t create the same feature changing only FIFA ranking position by FIFA ranking points because these columns are very negatively correlated, as you can see below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*XzQn-Z63RlHs11obj-7D0g.png" /><figcaption>Correlação das colunas de ranking</figcaption></figure><p>Then, it doesn’t make sense to create two versions of features like the weighted average game points by the ranking using rankings’ points and rankings’ positions, because they would yield the same result.</p><h4>Data Analysis</h4><p>Before the modeling, it’s needed to analyze what will be predicted. However the ideal is to predict between win, draw and lose, a 3-class classification problem is very hard to analyze and evaluate. Then, I decided to make the prediction between two classes: home team win and home team draw/lose.</p><p>To analyze the features in relation to the target, I’ll use violin plots and boxplots. The idea is to analyze how their distributions behave in relation to the values of each class, and if they can separate well the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*xSHciKB9r0HznNSVCWGifQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*376AD6myKzZRvWVwIUEqcw.png" /><figcaption>Violin plots of the first set of data</figcaption></figure><p>For the first set of data, the already created, only rank_dif, the difference between both teams’ rankings, has an impact on the target classes. Thus, I will create more features based on differences, since it seems that they are good predictors:</p><ul><li>Goals difference.</li><li>Suffered goals difference.</li><li>Difference between goals made by a team and suffered by the opponent.</li></ul><p>And again I analyzed the violin plots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*GVcbPsLHAMEjDY5EZq2I3g.png" /><figcaption>Violin plot of the new features</figcaption></figure><p>The difference between goals and suffered goals features have a good impact. However, the features that map the differences between goals made by a team and suffered by the opponent have no impact. Therefore, we have, now:</p><ul><li>Ranking difference.</li><li>Goal difference at the World Cup cycle and in the last 5 games.</li><li>Suffered goals difference at the World Cup cycle and in the last 5 games.</li></ul><p>Also, we could do the difference of points, difference of ranking position faced, and difference of points won by ranking faced. And, to weigh the level of the opponent, I thought of the following feature: difference between goals made by ranking faced, and the same to goals suffered.</p><p>The view by violin of this data is not very effective, due to the small scale. Then, I’ll analyze the boxplot of these data too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*15nWL48A49Zn3VGyrt9KJA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*6aeOfDJFpcvbIWGyiYTHzA.png" /><figcaption>Violin and Boxplot for the different features</figcaption></figure><p>Points difference, goals difference by ranking, points difference by ranking, and difference of ranking faced are good features. But, their version for the last 5 games and their version of the full cycle seems to be correlated. I’ll check this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*9qrUr0LgZHqEgrIrzdRMxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*lTOPT-9bJr-I_P6IfgR81A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*Q4qb6Cl6Ev4PprTlrziHRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*1APuvhymThVAK7rlF5EUEA.png" /><figcaption>Correlation of the features</figcaption></figure><p>Analyzing the correlation, it’s visible that in the difference of goals made by ranking the ideal is to choose only one of the versions, and I chose the one that considers the full cycle. For the others, it’s possible to use both versions.</p><p>Then, we have, as features:</p><ul><li>Difference between rankings (rank_dif)</li><li>Difference between goals’ average at the World Cup Cycle and in the last 5 games (goals_dif/goals_dif_l5)</li><li>Difference between suffered goals’ average at the World Cup Cycle and in the last 5 games (goals_suf_dif/goals_suf_dif_l5)</li><li>Difference between the average position of ranking faced at the World Cup Cycle and in the last 5 games (dif_rank_agst/dif_rank_agst_l5)</li><li>Difference between the goals weighted by the ranking faced’s average at World Cup Cycle (goals_per_ranking_dif)</li><li>Difference between the points weighted by the ranking faced’s average at World Cup Cycle and in the last 5 games (dif_points_rank/dif_points_rank_l5)</li><li>Categorical variable that indicates if it’s a friendly or not (is_friendly)</li></ul><p>With that, we have a database with the needed features to apply the Machine Learning model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*M4kWEcNfFzjwQL0kqS1zFA.png" /><figcaption>Some of the features of the database</figcaption></figure><h3>Model</h3><p>My idea here is to build two models, one of Random Forest and another of Gradient Boosting, and compare them to find which one is better, in order to be used in the simulation. I decided to use models based on decision trees because they did better in football problems when I studied the literature. Also, I don’t see the need to use more complex models, because of the size of the dataset.</p><p>I’ll do a parameter variation using SkLearn’s <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html">GridSearchCV</a>, and will use the best model at the simulation.</p><pre>from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier<br>from sklearn.model_selection import train_test_split, GridSearchCV<br><br>#separating the target from the features<br>X = model_db.iloc[:, 3:]<br>y = model_db[[&quot;target&quot;]]<br><br>#dividing the database<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= 0.2, random_state=1)<br>gb = GradientBoostingClassifier(random_state=5)<br>params = {&quot;learning_rate&quot;: [0.01, 0.1, 0.5],<br>            &quot;min_samples_split&quot;: [5, 10],<br>            &quot;min_samples_leaf&quot;: [3, 5],<br>            &quot;max_depth&quot;:[3,5,10],<br>            &quot;max_features&quot;:[&quot;sqrt&quot;],<br>            &quot;n_estimators&quot;:[100, 200]<br>         } <br>gb_cv = GridSearchCV(gb, params, cv = 3, n_jobs = -1, verbose = False)<br>gb_cv.fit(X_train.values, np.ravel(y_train))<br><br>#getting the best model<br>gb = gb_cv.best_estimator_</pre><p>I avoided testing a lot of parameters due to the delay in execution, prioritizing tests with values that reduce overfit, such as a learning_rate not so low and a n_estimators not so high.</p><p>Did the same to the Random Forest:</p><pre>params_rf = {&quot;max_depth&quot;: [20],<br>                &quot;min_samples_split&quot;: [5, 10],<br>                &quot;max_leaf_nodes&quot;: [175, 200],<br>                &quot;min_samples_leaf&quot;: [5, 10],<br>                &quot;n_estimators&quot;: [250],<br>                 &quot;max_features&quot;: [&quot;sqrt&quot;],<br>                }<br><br>rf = RandomForestClassifier(random_state=1)<br>rf_cv = GridSearchCV(rf, params_rf, cv = 3, n_jobs = -1, verbose = False)<br>rf_cv.fit(X_train.values, np.ravel(y_train))</pre><p>I analyzed the models with confusion matrix and ROC curve, and the results were:</p><pre>analyze(gb)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*w4D2sfxh1ZPrXRA4vNwnQw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*x4soCLwwEGXWfufL5hpiRA.png" /><figcaption>Gradient Boosting results</figcaption></figure><pre>analyze(rf)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*68WVyLXY4UgFTQC5gUVIyg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*WzlHRjiX4oS1aXmv51l_0w.png" /><figcaption>Random Forest results</figcaption></figure><p>Random Forest model has a slightly better performance but it seems to overfit. Analyzing AUC-ROC of Gradient Boosting, we see a model with almost the same performance but lower risk to overfit, that’s why it was chosen.</p><h4>World Cup Simulation</h4><p>Now, we arrived to the most interesting part: see which team the model will predict to win the World Cup!</p><p>The first thing to do is obtain the list of teams playing World Cup, and I used the method <a href="https://pandas.pydata.org/docs/reference/api/pandas.read_html.html"><em>read_html</em></a>, from Pandas. The method takes a dataframe from a web page, in which I put the <a href="https://en.wikipedia.org/wiki/2022_FIFA_World_Cup#Teams">Wikipedia</a> World Cup page. With that, I’ll recreate the World Cup table.</p><p>The table has the games, the points of each team in the group and a list storing the probabilities of the team winning each game. This will be used as tiebreaker in the case of two teams with the same points in the group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*TwLvzFuoYMC25WP80DeZ7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*IGYaaOWg3m9MjsAg17gCjg.png" /><figcaption>The first four groups in the created table and the first ten games of the World Cup</figcaption></figure><p>As I already explained, the model makes the classification between win from home team and win/draw from away team. Then, how can we predict draws? I created an objetive rule for this: knowing that all games from the World Cup are played on neutral venue, the prediction will be made in two forms:</p><ul><li>Team A x Team B (Simulation 1)</li><li>Team B x Team A (Simulation 2)</li></ul><p>If Team A or Team B wins both predictions, then the win is assigned to that team. In case one team wins in the first prediction and the other team wins in the second prediction, then it will be assigned as a draw. In the playoffs phase, the probabilities will be calculated in both predictions, and the team with the highest average probability advances. Since the model assigns a “win” to the away team even if it draws, the draw probability is inside the away team’s probability. So, with this type of simulate, both teams get a simulation with the draw as an advantage.</p><p>The data used in the simulation is until the last game of the team. In other words, for Brazil, the features will be calculated until the game against Tunisia, which was the last one that Brazil played.</p><p>Now, we can run a code simulating game-by-game, calculating the points and seeing what’s happening in the first phase.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be19ebdd3e44c4520ff8f44e2d7c3c50/href">https://medium.com/media/be19ebdd3e44c4520ff8f44e2d7c3c50/href</a></iframe><p>The outcome was:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00432fc80515fd3365d435bdb26f182b/href">https://medium.com/media/00432fc80515fd3365d435bdb26f182b/href</a></iframe><p>It’s interesting to see some results, such as the draw between Brazil and Switzerland and Denmark and France. In general, the favorites passed the group phase.</p><p>In the playoffs, the idea is the same:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3588627d293311da3db5a8020735ad99/href">https://medium.com/media/3588627d293311da3db5a8020735ad99/href</a></iframe><p>To see the results here, besides the text output, I decided to plot a graph with the playoff picture as done in <a href="https://www.kaggle.com/code/agostontorok/soccer-world-cup-2018-winner">this Kaggle notebook.</a> It’s a very interesting way to see the outcomes of these problems.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db78cba001fd36af7ef3539b515c80a9/href">https://medium.com/media/db78cba001fd36af7ef3539b515c80a9/href</a></iframe><p>The World Cup was simulated! My model is predicting a win from Brazil, with 56% of probability against England in the final! I think the biggest upsets were Belgium passing against Germany and England making it to the final, eliminating France in the quarter-final. It’s interesting to see some games in which the probability is very tight, as Netherlands vs. Argentina. From the quarter-final until the final, no team advanced with more than 60% of probability, which shows that the majority of the teams that advanced to playoffs are at a similar level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVNPb8z_8CD_V8_VRPqi0A.png" /><figcaption>Playoff picture</figcaption></figure><h4>Conclusion</h4><p>The idea of this project was to practice my knowledge in Machine Learning using something that I like, football. I thought that simulating the World Cup was very interesting, for being a trending topic nowadays that attracts the attention of everyone that likes the sport. I believe that the goal was achieved, since the construction of all features and the data analysis brought me the opportunity to search and meet a lot of new techniques.</p><p>About the results, I’m hoping a lot that the model predicts right the champion!</p><p>In case you can see the code in detail, you can see my <a href="https://github.com/sslp23/world_cup_sim">GitHub</a> and my <a href="https://www.kaggle.com/code/sslp23/predicting-fifa-2022-world-cup-with-ml">Kaggle</a>. And if you want to reach me, that’s my <a href="https://www.linkedin.com/in/sergio-pessoa-079317187/">LinkedIn</a>. Thanks!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*vkViD3Yp5TPDhJzx" /><figcaption>LatinX in AI (LXAI) logo</figcaption></figure><p><strong>Do you identify as Latinx and are working in artificial intelligence or know someone who is Latinx and is working in artificial intelligence?</strong></p><ul><li>Get listed on our directory and become a member of our member’s forum:<a href="https://lxai.app/"> https://lxai.app/</a></li><li>Become a writer for the LatinX in AI Publication:<a href="http://bit.ly/LXAI-Volunteer"> http://bit.ly/LXAI-Volunteer</a></li><li>Learn more on our website:<a href="http://www.latinxinai.org/"> http://www.latinxinai.org/</a></li></ul><p><strong>Don’t forget to hit the 👏 below to help support our community — it means a lot!</strong></p><p><strong>Thank you :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=640f1d2d7e98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/latinxinai/predicting-fifa-2022-world-cup-with-machine-learning-640f1d2d7e98">Predicting FIFA 2022 World Cup with Machine Learning</a> was originally published in <a href="https://medium.com/latinxinai">LatinXinAI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>