<?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 Robin van den Berg on Medium]]></title>
        <description><![CDATA[Stories by Robin van den Berg on Medium]]></description>
        <link>https://medium.com/@rvdb7345?source=rss-ac792da0cbfb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XQYEm6nN8o6GMs8dLKt5pQ.jpeg</url>
            <title>Stories by Robin van den Berg on Medium</title>
            <link>https://medium.com/@rvdb7345?source=rss-ac792da0cbfb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:26:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rvdb7345/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[Applying Trading Agents to the Commodity Market to Improve Procurement Strategies]]></title>
            <link>https://medium.com/vespertool/applying-trading-agents-to-the-commodity-market-to-improve-procurement-strategies-2fba0dd617e8?source=rss-ac792da0cbfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fba0dd617e8</guid>
            <category><![CDATA[commodities]]></category>
            <category><![CDATA[automated-trading]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[vesper]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <dc:creator><![CDATA[Robin van den Berg]]></dc:creator>
            <pubDate>Fri, 02 Dec 2022 12:39:28 GMT</pubDate>
            <atom:updated>2022-12-05T13:24:17.601Z</atom:updated>
            <content:encoded><![CDATA[<h4>From concept to the building and implementation of reinforcement learning agents</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*50QiIOPvyRxKsuCKOu0a0w.png" /><figcaption>AI-generated Image using Dall-E</figcaption></figure><p>Over the last five to ten years, reinforcement learning (RL) has attracted increasing interest from the artificial intelligence sector (<em>1</em>). Due to its recent interest, the adoption of reinforcement learning within real-world applications still needs to be improved. <a href="https://www.deepmind.com/">Deepmind</a> uses reinforcement learning to cool Google’s data centres, saving energy and reducing CO2 emissions (<em>2</em>). Reinforcement learning is also used for self-driving cars, healthcare, and trading applications. Do make sure to check out our other <a href="https://medium.com/vespertool/what-are-reinforcement-learning-trading-agents-and-why-you-need-them-when-trading-commodities-ed11b0749ab9">article</a> for a general introduction to reinforcement learning and trading agents, including a simple and intuitive example. This article explains what libraries can be used to set up a basic reinforcement learning trading agent from scratch, what features are needed for solving an RL task, and how we have set up these features for a commodity procurement agent. Finally, we will examine the results we achieved. It is evident that RL allows for a much more successful outcome than a basic buying strategy.</p><p>This article is published alongside a GitHub repo containing the code for the project if you want to check it out, you can have a look here: <a href="https://github.com/rvdb7345/Commodity-Trading-Agent">https://github.com/rvdb7345/Commodity-Trading-Agent</a>. And again, if you are not yet familiar with the concept of RL, you can have a look at our introductory article first, before diving into this one. Check it out here: <a href="https://medium.com/vespertool/what-are-reinforcement-learning-trading-agents-and-why-you-need-them-when-trading-commodities-ed11b0749ab9">https://medium.com/vespertool/what-are-reinforcement-learning-trading-agents-and-why-you-need-them-when-trading-commodities-ed11b0749ab9</a></p><p>An essential aspect of creating a Reinforcement Learning agent is to find an appropriate library that can be used for creating the trading environment. Table 1 below highlights four of the most exciting and valuable reinforcement learning libraries we came across. The <a href="https://github.com/openai/gym">OpenAI Gym library</a> was used to create our environment due to its compatibility with <a href="https://github.com/DLR-RM/stable-baselines3">StableBaselines3</a>, ease of use, and great documentation. StableBaselines3 lets us use state-of-the-art RL algorithms within the environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WkjujZv37QB_8aOM" /><figcaption><em>Table 1: Pros of RL libraries</em></figcaption></figure><h4><strong>Agents</strong></h4><p>The commodity market consists of three different personas: buyers, sellers (i.e. producers) and traders. The purpose of this article is to give an overview of what features are needed for creating an RL agent. In the following section, we will explain in more detail how we set up the environment, reward function and evaluation for our agent.</p><p>To train an RL agent, we need to design an environment in which the agent operates. The environment must provide the agent with information about the market’s state and allow the agent to take action that affects the market. The agent aims to maximise its reward function, which describes how the agent is supposed to behave. In the case of the buying agent, the total reward is defined as the amount paid for the product minus the total amount received. To evaluate the agent’s performance, one can compare the agent’s average reward over some time to the average reward of a benchmark agent, such as a buy-and-hold strategy. To give an overview of how we defined the environment, reward function and evaluation of the agent, each component is discussed in more detail below.</p><h4><strong>The Environment of the Buying Agent</strong></h4><p>The environment an agent is in can be thought of as a set of parameters and information the agent uses to perform an action. The parameters and rules of the agent are set as follows,</p><ul><li>Products cannot be consumed for an infinitely long time, and thus a fixed shelf-life is set.</li><li>There is a maximum amount of product that can be stored.</li><li>A minimum amount of product is needed for base production every time unit (e.g. weeks).</li><li>There is a fixed cost for storing a product in the warehouse (for costs such as rent and refrigeration).</li><li>A fixed cash amount is available for the agent every week.</li><li>A maximum quantity of product can be bought every week.</li><li>Every product unit has a fixed ordering cost (e.g. the transportation cost is expressed in a fixed price per unit).</li></ul><p>The agent needs more than just a set of rules and parameters to work with; it also requires some information to base its decisions on. To ensure the agent makes the best decisions possible, we provided it with information that is also available to buyers in the real world. This is done in the form of:</p><ul><li>A historical overview of the last n data points from the price development of the product itself.</li><li>A historical overview of the last n data points from some technical indicators created from the time series.</li><li>The current cash balance.</li><li>The current inventory level.</li></ul><h4><strong>Reward Function</strong></h4><p>The algorithm aims to produce an agent that can autonomously decide whether it should buy now or wait. For the algorithm to know what is good and bad, we assigned <strong>rewards</strong> and <strong>punishments</strong> based on its choice. We want the agent to buy in bulk if the future price is higher than the current price. Furthermore, we want to avoid the spoilage of products for environmental and economical reasons. This renders the following set of factors to consider:</p><ul><li>A reward is given for buying close to the lowest price in the next n weeks, where n is the shelf life. The shelf life is included because buying in bulk only makes sense if the product does not spoil before it is needed.</li><li>A punishment is given when the agent should have bought but did not (i.e. missing an opportunity).</li><li>A punishment is given when products are spoiled, which happens when the product cannot be consumed entirely before consumption. We assume a fixed level of consumption.</li><li>A punishment is given for performing emergency buys, executed when the buy quantity suggested by the agent is insufficient for the base consumption rate.</li><li>A punishment is given for going over the cash or storage buy limits. Although this is corrected in the simulation, the agents should learn not to do it.</li></ul><h4><strong>Evaluation</strong></h4><p>We can evaluate the RL agent by looking at its total reward over a specified period. However, this does not give insights into whether the agent performs better than an actual buyer. Therefore, instead of just focusing on the total reward, we have created a simple baseline model for evaluating the agent’s strategy. The baseline is a simple strategy where the agent buys the exact quantity consumed weekly, which is set to a fixed number.</p><h4><strong>Results</strong></h4><p>As indicated, we compared the performance of our buyer agent against the baseline of buying when the product is needed, not taking into account future price developments. We split our data into a 75% train and test split. This yields 1157 weeks (approx 22.25 years) of training data and 386 weeks (approx 7.4 years) of testing data. Because RL can be sensitive to its initiation, we accounted for stochasticity by repeating the training and evaluation 30 times.</p><p>For all repeats, the agent was trained for 20,000-time steps, taking approximately 45 seconds on an Apple M1 chip. The parameters used for these simulations are displayed in Table 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*r4n8f8rk0BlYqQDT" /><figcaption>Table 2: The parameters used in the simulation</figcaption></figure><p>The improvement over the baseline for our training set was found to be 59.17 ± 16.61%. In contrast, we found an improvement of 27.05 ± 9.57% for the test set. Performing a Wilcoxon signed-rank test to test whether the performance was significantly greater than the baseline (H1), we found a p-value of 1.863e-9 for both the training and the test set. This indicates that we can reject the null hypothesis that the agent has equal or worse performance than the baseline and conclude that we indeed created a better-performing buying agent.</p><p>Having concluded that the agent performs better than the baseline, we can look at the agent’s behaviour. Because we are interested in the buying strategy, we looked at the amount of product bought by the agent at every time step. We also checked the inventory level throughout the simulation. For the single run we inspect here, the improvement over the baseline for the train set and test set were 43.3570% and 39.9217%, respectively. The graphs show the price development where the data points are coloured according to the size of the buying quantity or the inventory level.</p><p>First, we look at the agent’s buys, shown in Figure 1 on the top row. We notice that the agent often buys when the price starts increasing. Considering the rewards, this is a logical approach. The agent is rewarded if it buys close to the lowest price of the next 13 weeks. When it is estimated that the price will increase over the following weeks, the agent will buy now and ensure the inventory is full enough to wait until the price is lower again. Because the product spoils after 13 weeks, it is impossible to buy at all the dips and wait out every peak. The agent will buy while the price is still rising but will attempt to stop before the price reaches the top. This way, the agent can buy at a lower price again after the price has gone down. We see this happening for the test set at approximately time steps 90 and 250.</p><p>Second, we take a look at the effect of this buying behaviour on the inventory level. In line with the buying approach of the agent, the inventory increases when the price starts increasing. Furthermore, from the bottom row of Figure 1, we can see that the inventory slightly decreases right before the highest price is reached. This makes a lot of sense as the agent buys large quantities when the price is increasing (leading to increasing inventory levels) and stops before reaching the peak price, as the price on the way down would be lower and thus more economical.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BBRCXJqn_-h6D3QF" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CLuTGKMcIVGGwAC5" /><figcaption>Figure 1: Overview of the quantity bought and inventory level over time for the train and test sets.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*akqRHp3yB1FdNS4F" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3OdvyJAPMB-lsMd_" /></figure><p>As the previous shelf life and storage availability only allowed buying 13 weeks in advance, we retrained the agent to work with a product that does not spoil for 52 weeks. This allows the agent to buy longer in advance and thus pick a better moment for buying the products it will need in the coming weeks.</p><p>Running this simulation, we found an improvement over the baseline of 235.6% and 133.3% for the train and test set, respectively. As expected, we see a more significant improvement over the baseline compared to the agent that could only buy 13 weeks in advance. In the figure below, we can look at the agent’s buying behaviour for the test set. The buys show a similar pattern to the simulation with a 13-week shelf life. The agent avoids buying before the top and on the way down, resuming buying again when it is close to the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rR3ws3hvLgLjGZLv" /><figcaption>Figure 2: The bought quantity over time for a product that can be stored for a year.</figcaption></figure><p>From the results above, we saw that the changing of parameter values greatly influences the performance of the agent. This raises the question: how much can you reduce your spending on product acquisition by training an RL agent to do it? We answered this question by retraining the agent using different shelf lives, assuming we have enough storage to store all the acquired products. This yields the results below where the agent was trained 30 times for every shelf life. The graph shows the improvement over the baseline as a function of the shelf life, where the light blue area indicates the standard deviation of the outcome. We see that the extra flexibility of a longer shelf life allows the agent to achieve a greater improvement over the baseline, just as one would expect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*84eStws33YaQCxDS" /><figcaption>Figure 3: The improvement over the baseline for different numbers of shelf lifes.</figcaption></figure><p>So what can we conclude from this? We see that RL allows us to significantly improve over a basic buying strategy. In addition, the flexibility of this setup will enable us to target a specific setting by changing the simulation parameters to form a digital twin of the buyer we are modelling. This serves as a proof of concept, showing the potential of RL. However, to improve, we can try a couple more things. Firstly, we can look at more data sources for the agent to enhance its ability to anticipate price movements. Currently, the agent only uses the time series itself and a set of technical indicators. However, Vesper has plenty of data resources, all of which could be used by the agent. Next to additional information, the parameters of the RL algorithm itself could be optimised. For this proof of concept, we mainly focussed on the environment and the rewards that guide the agent’s training. However, the model forming the agent’s brain could still be tweaked to get better performance. Lastly, we can make our digital buyer agent more accurate and life-like by including more considerations that a real-life buyer normally would consider by including them as part of our reward function.</p><p>If you want to check out the code for yourself, you can do so on this GitHub page: <a href="https://github.com/rvdb7345/Commodity-Trading-Agent">https://github.com/rvdb7345/Commodity-Trading-Agent</a></p><p>Written together with <a href="https://medium.com/u/324b32580606">Max de Bruijne</a>; Coded together with <a href="https://medium.com/u/c458acbdfcbe">Noah van grinsven</a></p><h3>References</h3><ol><li>Kaelbling, Leslie Pack, Michael L. Littman, and Andrew W. Moore. “Reinforcement learning: A survey.” <em>Journal of artificial intelligence research</em> 4 (1996): 237–285.</li><li><em>Safety-first AI for Autonomous Data Centre Cooling and Industrial Control</em>. RSS. (n.d.). Retrieved October 25, 2022, from <a href="https://www.deepmind.com/blog/safety-first-ai-for-autonomous-data-centre-cooling-and-industrial-control">https://www.deepmind.com/blog/safety-first-ai-for-autonomous-data-centre-cooling-and-industrial-control</a></li><li><em>Pricope, Tidor-Vlad. “Deep Reinforcement Learning in Quantitative Algorithmic Trading: A Review”. May 2021</em></li><li><em>Ali Shavandi, Majid Khedmati. “A multi-agent deep reinforcement learning framework for algorithmic trading in financial markets”, Expert Systems with Applications, Volume 208, 2022</em></li><li><em>Mosavi, A.; Faghan, Y.; Ghamisi, P.; Duan, P.; Ardabili, S.F.; Salwana, E.; Band, S.S. Comprehensive Review of Deep Reinforcement Learning Methods and Applications in Economics. Mathematics 2020, 8, 1640.</em></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fba0dd617e8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vespertool/applying-trading-agents-to-the-commodity-market-to-improve-procurement-strategies-2fba0dd617e8">Applying Trading Agents to the Commodity Market to Improve Procurement Strategies</a> was originally published in <a href="https://medium.com/vespertool">Vesper</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[World Cup 2022 Prediction: Paul the Octopus vs. Machine Learning]]></title>
            <link>https://medium.com/@rvdb7345/world-cup-2022-prediction-paul-the-octopus-vs-machine-learning-1c825038436d?source=rss-ac792da0cbfb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c825038436d</guid>
            <category><![CDATA[fifa-world-cup-2022-qatar]]></category>
            <category><![CDATA[match-prediction]]></category>
            <category><![CDATA[gradient-boosting]]></category>
            <category><![CDATA[tensorflow]]></category>
            <category><![CDATA[football-match-prediction]]></category>
            <dc:creator><![CDATA[Robin van den Berg]]></dc:creator>
            <pubDate>Tue, 15 Nov 2022 20:36:11 GMT</pubDate>
            <atom:updated>2022-11-16T03:57:23.565Z</atom:updated>
            <content:encoded><![CDATA[<h3>World Cup 2022 Prediction: Paul the Octopus<strong>†</strong> vs. Machine Learning - Can Data Beat Animal Instincts?</h3><p>Over the years, we have seen many stories about people or animals predicting the outcome of football matches, such as Paul the Octopus, Nelly the Elephant or Sijtje the Cow. Paul the Octopus, for example, was put to work predicting the scores of German games in the Euro 2008 and the 2010 World Cup, correctly predicting 12 out of 14 games, or 85.7%.</p><p>I probably know as much about football as Paul the Octopus, so when asked to participate in a football poule at work, I decided to give it a go. However, I decided to do it my way, instead of going by my incredibly poor knowledge of football. As a Data Scientist lacking the animal sixth sense, I opted for player statistics and Machine Learning models. So let&#39;s take a look at the process and see if a laptop and a couple of hours of free time can prevail in the football poule and perhaps even beat the animalistic gut feeling.</p><p>This article describes the general outline of this project. The details about the exploration, preprocessing and cleaning of the data are left out, but I might publish them later. If you want, you can already take a look yourself in this GitHub repo: <a href="https://github.com/rvdb7345/FootAI">https://github.com/rvdb7345/FootAI</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cj1T9viCDrXu5tdviTfmw.png" /><figcaption>A DALL-E 2 render of the epic battle between our model versus the octopus.</figcaption></figure><h3>The Goal</h3><p>We start where every project starts: defining our goal. Because I want to obtain the most points in the football poule, let&#39;s evaluate what gives us points and see what we can focus on.</p><p>For the group stage we can earn the following points (for the subsequent tournament stages, points are awarded for the same, but the points are a bit higher):</p><ul><li>Exact result: 90 points</li><li>Correct outcome win/draw/lose: 60 points</li><li>Correct country and position in the group: 75 points</li><li>Correct country but not position: 50 points</li><li>Top Scorers: goalkeepers and defenders: 64 points per goal</li><li>Top Scorers: midfielders: 32 points per goal</li><li>Top Scorers: forwards: 16 points per goal</li><li>Champion: 250 points</li></ul><p>I decided to focus on the match outcomes because these seem to yield the most points. So the objective is defined as follows: a Machine Learning model capable of predicting the outcome of the match.</p><h3>Collecting The Data</h3><p>Next step: what can and should we use for making these predictions? First of all, games to train the model on. This is where <a href="https://fixturedownload.com/">https://fixturedownload.com/</a> can help. This website contains the outcomes of a large collection of leagues from 2016 up until 2022, giving us a lot of matches to work with. In total, we have about 30k matches after scraping and combining the fixtures for all matches, dropping the ones that haven&#39;t been played yet.</p><p>The model will also need some features to actually predict the matches. We need data that we can create beforehand, so statistics about the previous matches won&#39;t help us much. For this project, I decided to go for a player-based approach, using the qualities of the players in a team to predict which team will win. Now, if you are about my age, you are likely already familiar with a bountiful source of football player data: FIFA by EA sports. Luckily for us, we can download statistics on all players for every FIFA game from 2015 up until 2022, providing player information such as value, speed, and so much more. You can find the datasets here: <a href="https://www.kaggle.com/datasets/stefanoleone992/fifa-22-complete-player-dataset">https://www.kaggle.com/datasets/stefanoleone992/fifa-22-complete-player-dataset</a>.</p><h3>Building the Teams and Creating the Features</h3><p>Now that we have some data, we need features next. To go ahead with our player-based approach, we need to create teams. One thing though, we don’t know who played during the matches we have collected and we don’t know in which formation. So we make our first assumption: every game was played with the best possible team for the best possible formation. This means we skip over possible injuries, red cards or resting players, purely due to a lack of accessible information.</p><p>So, for each team, we do the following:</p><ol><li>Decide whether the game is an international game or from another league</li><li>Get the players with that nationality/from the correct team from the year the match was played</li><li>Loop through the possible formations and check the best player for each position</li><li>Select the formation with the highest cumulative score</li></ol><p>The formations we consider are listed below.</p><pre>formations_dict = {<br>    &#39;4-3-1-2&#39;: [&#39;GK&#39;, &#39;RB|RWB&#39;, &#39;LCB|CB&#39;, &#39;RCB|CB&#39;, &#39;LB|LWB&#39;, &#39;CDM|CM&#39;, <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;CAM|CF&#39;, &#39;CF|ST&#39;, &#39;CF|ST&#39;],<br>    &#39;4-3-2-1&#39;: [&#39;GK&#39;, &#39;RB|RWB&#39;, &#39;LCB|CB&#39;, &#39;RCB|CB&#39;, &#39;LB|LWB&#39;, &#39;CDM|CM&#39;, <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;CAM|CF&#39;, &#39;CAM|CF&#39;,<br>                &#39;CF|ST&#39;],<br>    &#39;4-3-3&#39;:   [&#39;GK&#39;, &#39;RB|RWB&#39;, &#39;LCB|CB&#39;, &#39;RCB|CB&#39;, &#39;LB|LWB&#39;, &#39;CDM|CM&#39;, <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;RW|RF|ST&#39;, &#39;CF|ST&#39;, &#39;LW|LF|ST&#39;],<br>    &#39;4-4-2&#39;:   [&#39;GK&#39;, &#39;RB|RWB&#39;, &#39;RCB|CB&#39;, &#39;LCB|CB&#39;, &#39;LB|LWB&#39;, &#39;RM|RW&#39;, <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;LM|LW&#39;, &#39;CF|ST&#39;, &#39;CF|ST&#39;],<br>    &#39;4-5-1&#39;:   [&#39;GK&#39;, &#39;RB|RWB&#39;, &#39;RCB|CB&#39;, &#39;LCB|CB&#39;, &#39;LB|LWB&#39;, &#39;RM|RW&#39;, <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;LM|LW&#39;, &#39;CF|ST&#39;, &#39;CF|ST&#39;],<br>    &#39;3-4-1-2&#39;: [&#39;GK&#39;, &#39;RCB|CB&#39;, &#39;CB&#39;, &#39;LCB|CB&#39;, &#39;RM|RW&#39;, &#39;CDM|CM&#39;,  <br>                &#39;CDM|CM&#39;, &#39;LM|LW&#39;, &#39;CAM|CF&#39;, &#39;CF|ST&#39;, &#39;CF|ST&#39;],<br>    &#39;3-4-3&#39;:   [&#39;GK&#39;, &#39;RCB|CB&#39;, &#39;CB&#39;, &#39;LCB|CB&#39;, &#39;RWB|RM&#39;, &#39;CDM|CM&#39;,  <br>                &#39;CDM|CM&#39;, &#39;LWB|LM&#39;, &#39;RW|RF|ST&#39;, &#39;CF|ST&#39;, &#39;LW|LF|ST&#39;],<br>    &#39;3-5-2&#39;:   [&#39;GK&#39;, &#39;RCB|CB&#39;, &#39;CB&#39;, &#39;LCB|CB&#39;, &#39;RM|RWB|RB&#39;, &#39;CDM|CM&#39;,  <br>                &#39;CDM|CM&#39;, &#39;CDM|CM&#39;, &#39;LM|LWB|LB&#39;, &#39;CF|ST&#39;, &#39;CF|ST&#39;]<br>}</pre><p>After we have gathered the best 11 players, we can start to create some features. For the current model, we aggregate the attributes of the players per line in the field, namely the goalkeeper, the defenders, the midfielders, and the forwards. Here, we define the chosen attributes that are important for each specific line (most of it speaks for itself, but I flew in a football expert to double-check it, big thanks to <a href="https://medium.com/u/324b32580606">Max de Bruijne</a>). In the code block below, I define the features per line. The general list contains features that are created for each line. The field list describes the features that matter for all players except the goalkeeper. The other lists speak for themselves.</p><pre>features_to_extract = {<br>    &#39;general&#39;: [&#39;value_eur&#39;, &#39;potential&#39;, &#39;overall&#39;, &#39;work_rate&#39;, <br>                &#39;international_reputation&#39;, &#39;age&#39;, &#39;height_cm&#39;,<br>                &#39;weight_kg&#39;, &#39;shooting&#39;, &#39;passing&#39;, &#39;defending&#39;,  <br>                &#39;physic&#39;, &#39;power_shot_power&#39;, &#39;power_jumping&#39;,  <br>                &#39;power_stamina&#39;, &#39;power_strength&#39;, &#39;power_long_shots&#39;,<br>                &#39;mentality_interceptions&#39;, &#39;mentality_positioning&#39;,  <br>                &#39;mentality_vision&#39;, &#39;mentality_penalties&#39;,  <br>                &#39;mentality_composure&#39;, &#39;league_level&#39;],<br>    &#39;field&#39;: [&#39;skill_dribbling&#39;, &#39;skill_curve&#39;, &#39;skill_fk_accuracy&#39;,  <br>              &#39;skill_long_passing&#39;, &#39;skill_ball_control&#39;,<br>              &#39;mentality_aggression&#39;, &#39;pace&#39;, &#39;dribbling&#39;,  <br>              &#39;movement_acceleration&#39;, &#39;movement_sprint_speed&#39;,<br>              &#39;movement_agility&#39;, &#39;movement_reactions&#39;, &#39;movement_balance&#39;,  <br>              &#39;weak_foot&#39;, &#39;skill_moves&#39;],<br>    &#39;goal&#39;: [&#39;goalkeeping_diving&#39;, &#39;goalkeeping_handling&#39;,  <br>             &#39;goalkeeping_kicking&#39;, &#39;goalkeeping_positioning&#39;,  <br>             &#39;goalkeeping_reflexes&#39;, &#39;goalkeeping_speed&#39;],<br>    &#39;def&#39;: [&#39;defending_marking_awareness&#39;, &#39;defending_standing_tackle&#39;,  <br>            &#39;defending_sliding_tackle&#39;],<br>    &#39;att&#39;: [&#39;attacking_crossing&#39;, &#39;attacking_finishing&#39;,  <br>            &#39;attacking_heading_accuracy&#39;, &#39;attacking_short_passing&#39;,<br>            &#39;attacking_volleys&#39;]<br>}</pre><p>We compose these features for the home team and the away team separately. In addition, we add a comparative feature where we subtract the away team feature value from the home team feature value.</p><p>Some of the games in the fixture data set have to be dropped because we can not create a team due to a lack of players in the FIFA dataset. For every game, we add a binary feature indicating whether the game was an international game or not. After dropping all the incomplete teams, we are left with 25350 games.</p><h3>Training the Model and Evaluating the Performance</h3><p>Having tried out a fair few models, including a variety of deep neural net architectures, a gradient boosting machine had the best performance and the best speed. The dataset is split into a train and test set with an 80–20 split. The target variable is set as the difference in goals between the home and the away team. We cap the goal difference at an absolute difference of 4 goals to prevent the effects of outliers.</p><p>The model is created using the <strong>TensorFlow Decision Forests</strong> (<strong>TF-DF</strong>) library. The supplemental neural network architectures were constructed using the Keras API.</p><p>After training the model and evaluating it on the test set, we check the mean absolute error (MAE) in the goal difference. We also convert the predicted scores into a win/draw/lose for the home team and check the accuracy of that prediction.</p><p>We find:</p><ul><li>MAE — Training set: 0.43, Test set: 0.56</li><li>Accuracy — Test set: 83.2%</li></ul><p>This means that on the test set we are on average 0.56 goals off, where we are able to predict the right class for approximately 83% of the matches.</p><p>So sadly, on the test set, we just underperform Paul the Octopus.</p><p>That brings us to our ultimate goal: predicting the FIFA World Cup 2022. Because the matches for the group phase have been announced, that is what we predict here. Below you can see the output of the model. (You might notice the games played by Qatar and Tunisia aren’t in this overview. This is because the FIFA player dataset doesn’t contain a complete team of eleven players for these countries. It does not include any players from Qatar and no goalkeepers from Tunisia. For my own predictions, I substituted those teams with Saudi Arabia and Costa Rica respectively since they rank one place below the corresponding teams in the <a href="https://www.fifa.com/fifa-world-ranking/men?dateId=id13792">FIFA world ranking</a>.)</p><pre>          HomeTeam        AwayTeam  goal_difference  rounded_diff<br>1          England            Iran         2.230912             2<br>2          Senegal     Netherlands        -1.312857            -1<br>3              USA           Wales        -0.364515             0<br>4        Argentina    Saudi Arabia         2.844887             3<br>6           Mexico          Poland        -0.219258             0<br>7           France       Australia         2.213196             2<br>8          Morocco         Croatia         0.507928             1<br>9          Germany           Japan         1.742433             2<br>10           Spain      Costa Rica         1.496389             1<br>11         Belgium          Canada         0.001733             0<br>12     Switzerland        Cameroon         0.545694             1<br>13         Uruguay  Korea Republic         1.760429             2<br>14        Portugal           Ghana         1.164370             1<br>15          Brazil          Serbia         1.018560             1<br>16           Wales            Iran         1.429190             1<br>18     Netherlands         Ecuador         1.235533             1<br>19         England             USA         1.433627             1<br>21          Poland    Saudi Arabia        -0.130828             0<br>22          France         Denmark         1.590021             2<br>23       Argentina          Mexico        -0.229942             0<br>24           Japan      Costa Rica        -0.502349            -1<br>25         Belgium         Morocco         0.731527             1<br>26         Croatia          Canada         1.268350             1<br>27           Spain         Germany         0.871285             1<br>28        Cameroon          Serbia        -1.374333            -1<br>29  Korea Republic           Ghana        -1.524515            -2<br>30          Brazil     Switzerland         1.315612             1<br>31        Portugal         Uruguay         0.282937             0<br>32         Ecuador         Senegal         0.113329             0<br>34           Wales         England        -1.415040            -1<br>35            Iran             USA        -1.533749            -2<br>36       Australia         Denmark        -0.241529             0<br>38          Poland       Argentina         0.063945             0<br>39    Saudi Arabia          Mexico        -0.629729            -1<br>40         Croatia         Belgium        -0.908118            -1<br>41          Canada         Morocco        -1.262738            -1<br>42           Japan           Spain        -1.912954            -2<br>43      Costa Rica         Germany        -1.944935            -2<br>44           Ghana         Uruguay        -1.740785            -2<br>45  Korea Republic        Portugal        -1.249199            -1<br>46          Serbia     Switzerland         1.090324             1<br>47        Cameroon          Brazil        -1.485124            -1</pre><h3>Where does that leave us?</h3><p>Although it seems Paul the Octopus still triumphs over my somewhat more modern approach, the latter does seem to have some benefits. Where Paul was only able to predict German matches, the model developed here generalises to every game for which we can compose the teams, thus offering us quite a bit of flexibility. Also definitely not unimportant, you don’t have to clean an aquarium or worry about the living conditions of a living animal.</p><p>To improve our model, we can think about a couple more things. For example, you can try to find the times at which players were injured for the past few years to improve the accuracy of the team compositions. Or, one could include the previous performance of the teams. There are a lot of possibilities that could be explored and I invite you all to try them out, find new data to enrich the current information and share your findings!</p><p>The goal is to write a couple more articles on this subject. Some of the subject ideas are: taking a more in-depth look at the data processing, exploring the other models that were created and using SHAP values to explain the predictions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c825038436d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>