<?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 Nicholas Amirsoleimani on Medium]]></title>
        <description><![CDATA[Stories by Nicholas Amirsoleimani on Medium]]></description>
        <link>https://medium.com/@nick-amir?source=rss-8bbc7723c8fb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CQyEbxg7igF2d4tmqycOcA.png</url>
            <title>Stories by Nicholas Amirsoleimani on Medium</title>
            <link>https://medium.com/@nick-amir?source=rss-8bbc7723c8fb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 08:55:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nick-amir/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[PredictNow.ai — A step to the new generation for machine learning in finance]]></title>
            <link>https://nick-amir.medium.com/predictnow-ai-a-step-to-the-new-generation-for-machine-learning-in-finance-26fac1bdcb61?source=rss-8bbc7723c8fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/26fac1bdcb61</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Nicholas Amirsoleimani]]></dc:creator>
            <pubDate>Mon, 16 Aug 2021 23:24:28 GMT</pubDate>
            <atom:updated>2022-01-21T19:38:33.737Z</atom:updated>
            <content:encoded><![CDATA[<h3>PredictNow.ai — A gentle yet powerful pathway to machine learning in finance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KxqZZmMrj5z8Bh7L" /></figure><p>Classical statistical methods have been dominating the finance realm for decades. While these methods were once powerful and could untangle complex patterns, today, they cannot always capture the complexities of the current generation’s markets. Machine learning is the newest set of techniques based on classical statistics that can in fact untangle these complex patterns and is gaining traction each day within the finance industry. However, because it is quite modern and fairly sophisticated, the barrier to entry to this field is rather high. There are many complicated subjects within machine learning and mastery or even fluency of it takes a strong quantitative background and many hours of trial-and-error.</p><p>PredictNow.ai is a website that simplifies this field and presents it in a gentler way while simultaneously still providing users the same amount of power that some of the most advanced machine learning algorithms can deliver. It allows users to store data and use computing power for free with a trial while giving the option to purchase more of these resources down the road. This article will demonstrate how to use PredictNow.ai and why it is an excellent introduction to machine learning for newer users. For a more in-depth guide, visit the <a href="https://www.predictnow.ai/get-manual/">PredictNow.ai</a> website to view the manual.</p><h3>Obtaining Data</h3><p>The first step to using this website is to obtain and import data. This data does not strictly have to be financial; it can be anything that has features meant to predict some value. This can be the weather, people’s age, the chance of being diagnosed with heart disease, etc. In this example, we will use a sample dataset given directly from the website that involves many features about the S&amp;P 500 index meant to predict future returns. A sample of this data is shown in Table 1 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*b5bWbvz-tAoeV2HzmIJBlg.png" /><figcaption>Table 1: Sample of S&amp;P financial features</figcaption></figure><h3>Importing and Setting Hyperparameters</h3><p>Once the data is imported, various hyperparameters can be set. The hyperparameters that are included provide the user with a great deal of flexibility depending on the type of data they are using.</p><ul><li><strong>Time-Series:</strong> Whether or not the data has a time component and is sorted chronologically</li><li><strong>Prediction Type: </strong>Allows classification and regression form targets</li><li><strong>Feature Selection: </strong>Shapley Additive Explanations (SHAP) to use Shapley values or Cluster Mean Decrease in Accuracy (Cluster MDA) to use hierarchical clustering with MDA values</li><li><strong>Seed Value: </strong>To allow the user to recreate the same set of random initializations</li><li><strong>Test Set Size:</strong> The proportion of the data to be reserved purely for testing</li><li><strong>Ensemble Learning Type:</strong> Gradient Boosted Decision Trees (GBDT) or Dropouts meet Multiple Additive Regression Trees (DART) for the method of combining weak learning</li><li><strong>Sample Weights:</strong> Whether sample weights are to be used in the model</li><li><strong>Probability Calibration:</strong> Allows probability calibration for the data</li><li><strong>Exploratory Data Analysis:</strong> Provides sample statistics about the data such as the features’ means, standard deviations, quartiles, etc.</li></ul><p>Once the hyperparameters are set, the model can then be evaluated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6N059C1c3Z6nxh4hBFbZdQ.png" /><figcaption>Figure 1: Hyperparameter selection screen</figcaption></figure><h3>Interpreting Results</h3><h4>Initial Results</h4><p>The results of the model initially show the basic scores of how the model performed on the training and test sets. These values can be used to assess the model’s performance and tune the hyperparameters to optimize the model. It also can be used to evaluate different features and their importance. This is helpful because the more superfluous features there are, the less accurate the model will be. As shown in Figure 2, the p-value for the training dataset is 0.01 and the p-value for the testing dataset is 8.37E-11 showing that the model did in fact find predicting power within the features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*nHXMyZmPYwBTvKqHPU_m7A.png" /><figcaption>Figure 2: Initial results of the model</figcaption></figure><h4>Feature Importance</h4><p>Another important aspect to understanding the model is determining which features are actually significant. PredictNow.ai allows the user to understand which of their features were the most important in determining the outcome of the targets. Once this is depicted, a baseline score (~0.015 in this case) can be used and the model can be trained again only using features above this value. As mentioned previously, this will hopefully improve the accuracy of the model and is generally good practice within utilizing these models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*CzsjRPDxO2Pr71faKt4kXQ.png" /><figcaption>Figure 3: Feature importance depiction</figcaption></figure><h4>Fractional Differentiation</h4><p>Another neat technique that this website allows the user to utilize is fractional differentiation. This transforms nonstationary data into stationary data while retaining the most amount of information. The transformed data can be down in Figure 3 below. Note that in some columns, the data is unchanged, and this is because the data was already stationary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mCmm62s2HncmYJy1kQhqNw.png" /><figcaption>Figure 3: Fractionally differentiated features</figcaption></figure><h3>Final Thoughts</h3><p>Overall, PredictNow.ai is a beautifully designed website that is allowing people who are interesting in machine learning but don’t quite have the background to develop their own models from scratch to still be able to utilize advanced algorithms. It has a very pleasant user-interface, free storage and computing power, and an elementary yet powerful set of tools that anyone can learn to use. For future improvement of the website, it would be nice to see more visual representations of results such as confusion matrices or correlation heatmaps. It would also be helpful if there were more machine learning algorithms to choose from such as linear regressions and SVMs. However, I am hopeful that this website and those that are similar will develop over time to implement these features as well as many others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26fac1bdcb61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beat the Bookmakers With Tree-Based Machine Learning Algorithms]]></title>
            <link>https://medium.com/analytics-vidhya/beat-the-bookmakers-with-tree-based-machine-learning-algorithms-1d349335b54?source=rss-8bbc7723c8fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d349335b54</guid>
            <category><![CDATA[creativity]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random-forest]]></category>
            <category><![CDATA[boosting]]></category>
            <category><![CDATA[sports-betting]]></category>
            <dc:creator><![CDATA[Nicholas Amirsoleimani]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 00:50:18 GMT</pubDate>
            <atom:updated>2022-01-12T22:41:14.837Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ELY79N6nrV6YHyL6.jpg" /><figcaption><a href="http://www.circledgame.com/mlb-stats.php?id=errors-per-game&amp;name=Errors%20Per%20Game">Source</a></figcaption></figure><p><a href="#ccf6">Introduction<br></a><a href="#1e2a">Basics of Machine Learning Algorithms<br></a><a href="#1eb6">Decision Trees<br></a><a href="#c7a1">Tree-Based Algorithms<br></a><a href="#01c5">Data Acquisition and Preprocessing<br></a><a href="#32e9">Feature Engineering</a><br><a href="#8c39">Machine Learning Infrastructure</a><br><a href="#2327">Initial Results and Optimization<br></a><a href="#1462">Final Results and Testing Betting Strategies<br></a><a href="#84e9">Conclusion</a></p><blockquote>All of the programming was done in MATLAB, but this article will not discuss any coding syntax nor anything specific to how to implement these ideas within a programming interpreter. This is simply the methodology behind the steps of creating a model. The data was gathered from <a href="https://www.baseball-reference.com/">here</a> and <a href="https://www.sportsbookreviewsonline.com/scoresoddsarchives/mlb/mlboddsarchives.htm">here</a>.</blockquote><h3>Introduction</h3><p>Sports are one of the few types of entertainment overlapping in nearly every culture throughout all of mankind. The rivalry, teamwork, and seemingly unpredictability of them cultivate massive fans around the world and are established as one of many people’s top pastimes. However, through the advent of modern machine learning, we will try to do the impossible and unravel this uncertainty. <strong>Specifically, this article will attempt to predict whether the home team of a baseball game will win or lose with various tree-based algorithms.</strong></p><p>Well, why baseball and why tree-based algorithms? The answer to the former is that <strong>baseball is a relatively popular sport with a</strong> <strong>large history of data</strong>. It is also a sport that<strong> involves many players</strong>; if one player is not feeling very well a particular game, the rest of the team will hopefully make up for him unlike in an individual sport such as tennis (although it’s certainly possible that one could use a model to predict tennis scores and even get great results). This will hopefully make predicting the winners an easier task. As far as the latter question, <strong>tree-based algorithms are one of the most popular types of algorithms</strong> used in classification machine learning, so this article will hopefully teach the reader about one possible way of applying a tree-based algorithm from start to finish.</p><h3>Basics of Machine Learning Algorithms</h3><p>There are two primary forms of machine learning algorithms:<strong> supervised learning </strong>and <strong>unsupervised learning</strong> (there is also reinforcement learning but we’ll ignore this for now). Supervised learning is when you give a model an <strong>input <em>and</em> an output</strong>, so that the model can learn how to estimate the output given the input. Supervised learning has two primary sub-categories: <strong>classification and regression</strong>. Classification problems have outputs that are <strong>discrete classes</strong>, such as win or lose, whereas regression problems have outputs that are <strong>continuous</strong>, such as price. On the other hand, unsupervised learning<strong> <em>only</em> uses inputs </strong>and tries to cluster them together using various metrics.</p><p>For example, let’s say I want to predict someone’s gender based on their weight and height. The <strong>inputs</strong> (also known as <strong>features, predictors, covariates, independent variables, or regressors</strong>) to the model would be the weight and height, whereas the <strong>output</strong> (also known as <strong>target, dependent variable, or response</strong>) would be biological sex. This particular problem would be supervised since you are giving the model an input and an output. More specifically, it would be supervised classification problem since biological sex only has two classes. If we were predicting weight instead, it would be a supervised regression problem since weight is continuous.</p><h3>Decision Trees</h3><p>There are many different machine learning techniques for classification, but some of the most popular ones are tree-based algorithms. Tree-based algorithms use <strong>collections of decision trees</strong> to make predictions. A decision tree is itself an algorithm that can be used for regression and classification. Essentially, a decision-tree is a sequence of questions that partitions data by asking whether certain features are under or over a specific value, then makes predictions of the target by utilizing the partitions. A standard configuration of a decision tree is depicted in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*CiFNS-nPOX3FNDQLR_n4Nw.png" /><figcaption>Figure 1: Decision tree with height and weight features and a biological sex target</figcaption></figure><p>There are three components to a decision tree:</p><ul><li><strong>Root Node: </strong>The first decision split in the tree</li><li><strong>Internal Nodes: </strong>All subsequent decision splits</li><li><strong>Leaf Nodes: </strong>The final layer of the tree that classifies the groups into the target variable</li></ul><p>In the tree above, the root node is the node containing the split Height &gt; 67.5 in., the only internal node is the node containing the split Weight &gt; 160 lbs, and the leaf nodes are the nodes containing the target variables (pink diamonds in this case).</p><h4>Split Criterion</h4><p>But, how do decision trees decide what splits to use? To explore this, let’s use our example from above and imagine that we are trying to predict biological sex given someone’s weight and height with a decision tree. As noted in Figure 1, most decision trees split a set of data into two separate groups that best split the data according to some metric. For classification, the two primary metrics used are <strong>Gini Impurity</strong> and <strong>cross-entropy</strong>. Cross-entropy is similar to Gini Impurity, but it involves using the concept of entropy from information theory. This article won’t go in depth about it, but essentially, as the cross-entropy decreases, the homogeneity within the groups increases. Therefore, we want to <strong>minimize cross-entropy</strong>. Both decision tree splitting methods are widely used since they are differentiable, but Gini Impurity is usually preferred since it is less computationally expensive and therefore will be used in this project. Once a decision tree makes a split on the data, it <strong>continues to keep making splits until some criterion is met</strong>. The criterion can be the number of leaf nodes, the minimum splitting criteria value for each leaf, the number of splits, etc.</p><h4><strong>Gini Impurity</strong></h4><p>Gini Impurity measures the <strong>likelihood of incorrectly classifying a random element from a partition given that it was classified according to the distribution of the classes</strong>. The specific formula is given above, where K is the number of classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQu8U-NkFRTvuMGI_44bEQ.png" /><figcaption>Gini Impurity Definition</figcaption></figure><p>Image we have a group of 100 individuals, 60 of which are male and the other 40 are female. The probability of picking a male is 0.6 and the probability of classifying him incorrectly is 1-0.6. Conversely, the probability of picking a female is 0.4 and the probability of incorrectly classifying her is 1–0.4. Therefore, the Gini Impurity for this group would be 0.6*(1-0.6)+0.4*(1-0.4)=0.48. If we used the last simplification, the equation would be 1–0.6²-0.4²=0.48. This alternative formulation can also be thought of as the complement of the probability of correctly classifying each sample. The higher the Gini Impurity, the higher the probability of incorrectly classifying a member of the group, which is why <strong>we want to <em>minimize</em> this value</strong>. A decision tree using Gini Impurity as its split criteria will find which feature split minimizes the weighted sum of the two new groups Gini Impurity, where the weights are the percentage of observations in each leaf.</p><h3>Tree-Based Algorithms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SouOgawfNN7cfpoT.png" /><figcaption>Figure 2: Collection of decision trees (<a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fmedium.com%2Frapids-ai%2Faccelerating-random-forests-up-to-45x-using-cuml-dfb782a31bea&amp;psig=AOvVaw1yixGzkRRKrl4NRwCmj0z2&amp;ust=1618445771511000&amp;source=images&amp;cd=vfe&amp;ved=0CA0QjhxqFwoTCOjmuc26_O8CFQAAAAAdAAAAABAD">Source</a>)</figcaption></figure><p>A simple decision tree can individually produce very accurate results on the data it is trained on. However, this data is usually <strong>overfit on its training data</strong> and therefore would not have as low of an error on subsequent samples that were not used to train it. This is why decision trees alone are referred to as <strong>weak learners</strong>. There are two primary ideas to prevent overfitting: limit the number of splits on a tree and average the decisions of many trees. If we limit the number of splits on a tree to, say, 4, the tree will certainly be less overfit, but <strong>many complex relationships between the data would be ignored </strong>since only a maximum of 4 features will be used. Therefore, it is commonly preferred to create many overfit decision trees and find some way to incorporate all of them to make one decision. This is where tree-based algorithms come in to play. Tree-based algorithms are classified as ensembles in which many weak learning (decision-trees in this case) are combined to make a strong learner. Different algorithms have different ways of building these trees and combining them. The two primary algorithms used are ones that rely on <strong>bootstrap aggregation</strong> and ones that rely on <strong>boosting</strong>.</p><h4>Bagging</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/0*iH1oedESf9AVsyg9.png" /><figcaption>Figure 3: Standard bagging configuration (<a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FBootstrap_aggregating&amp;psig=AOvVaw1W11n7f5ku5zfG-6m5T6dz&amp;ust=1618445901480000&amp;source=images&amp;cd=vfe&amp;ved=0CA0QjhxqFwoTCMCY_P26_O8CFQAAAAAdAAAAABAJ">Source</a>)</figcaption></figure><p><strong>Bootstrap aggregation, otherwise known as</strong> <strong>bagging, selects random samples with replacement from our original data set to fit predictions on</strong>. Imagine we have our original data set of predicting biological sex from our various features. If we fit a decision tree on our all of our data, well, that’s it. We don’t have any more data so that is the only decision tree that can be made. If, however, we used bagging, we would sample M data points from our original dataset with replacement and fit a decision tree on that new sample. M is generally equal to N where N is the number of original data points. If M is equal to N, then it can be shown that on average, 1/e or <strong>36.8% of the original data points were not used</strong>. This is because we have sampled with replacement, so many points were chosen more than once. Now, <strong>repeat this process many times and choose some criteria for predicting the output</strong>, such as the majority vote of the all the decision-trees. This process has been shown to <strong>decrease the variance</strong> in a model and is usually preferred with some algorithms, like <strong>random forest</strong>.</p><h4><strong>Random Forest</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/0*46-4uwqK1A7BZBRj.png" /><figcaption>Figure 4: Random forest schematic (<a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Flevelup.gitconnected.com%2Frandom-forest-regression-209c0f354c84&amp;psig=AOvVaw0GY9syzsiCNJwXGEqozPDD&amp;ust=1618446099570000&amp;source=images&amp;cd=vfe&amp;ved=0CA0QjhxqFwoTCKjcpOe7_O8CFQAAAAAdAAAAABAD">Source</a>)</figcaption></figure><p><strong>Random forest</strong> is a machine learning algorithm that can be used for classification and regression. The algorithm essentially constructs many different decision trees using bagging and either <strong>averages out the predictions of each tree for regression or takes the majority vote of the trees for classification</strong>. It is widely used over decision trees since it tends to reduce <strong>overfitting</strong>. What makes it unique from previous majority vote bagging algorithms is that it only<strong> selects a random subset of the features at each tree split.</strong> Generally, for classification problems, sqrt(p) predictors are used and for regression problems, p/3 predictors are used where p is the total number of features. If there were a few strong predictors, they would be used in every tree making the trees strongly correlated. This makes utilizing multiple trees more futile since they will all have similar predictions. By selecting a subset of predictors at each split, the tree cannot always use the strongest predictors and is forced to try to find patterns within other features. This creates less correlated trees and usually causes an increase in test data accuracy.</p><h4><strong>Boosting</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/0*CvrsvHOz72bU4i48.png" /><figcaption>Figure 5: Standard boosting schematic (<a href="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Ftowardsdatascience.com%2Funderstanding-adaboost-2f94f22d5bfe&amp;psig=AOvVaw37bbdyDzWIzF2Wg6s1H507&amp;ust=1618446235316000&amp;source=images&amp;cd=vfe&amp;ved=0CA0QjhxqFwoTCIjP0qm8_O8CFQAAAAAdAAAAABAE">Source</a>)</figcaption></figure><p>Boosting is also an ensemble-based machine learning algorithm based on trees. There are many different algorithms that each have their own unique properties so I will not go in depth about each one, but essentially, they <strong>iteratively train each tree by trying to improve the weaknesses of previous trees trained</strong>. In a random forest, each tree is trained independently of how other trees performed. However, in boosting, each tree tries to fix the mistakes previous trees made. This involves weighting certain observations differently, minimizing specific loss functions, and other nuances. To further prevent overfitting, these trees are also usually either tree stumps (one-level decision tree) or shallow decision trees (maybe something like 10 splits).</p><p>The in-depth algorithms would not be within the scope of this article, so it will not go in depth about them, but there are many resources online showcasing them. Some of the most common boosting algorithms are AdaBoost, LPBoost, TotalBoost, XGBoost, LogitBoost, and RUSBoost.</p><h3>Data Acquisition and Preprocessing</h3><p>Before starting, it’s important to understand that a large part of performing machine learning is simply gathering, cleaning, and processing data before use. The steps used in for this process are:</p><ul><li><strong>Gather Data (web scraping or API)</strong></li><li><strong>Fill missing data (or using surrogate splits)</strong></li><li><strong>Remove Outliers</strong></li><li><strong>Normalize or standardize data</strong></li></ul><h4>Gather Data</h4><p>First, we need to actually acquire the data. APIs are usually faster and more convenient, but may not always exist for your specific case or be too expensive. In this case, web-scraping was used with BeautifulSoup4 in python.</p><h4>Fill Missing Data</h4><p>Some common techniques to filling missing feature points are through the use of that feature’s mean, linear interpolation, shape-preserving piecewise cubic spline interpolation, and modified Akima cubic Hermite interpolation. However, some machine learning algorithms have methods of bypassing missing values, such as using<strong> surrogate splits</strong>. <strong>A surrogate split is simply a</strong> <strong>split that is used when the original value is missing</strong>. For example, let’s say that our decision tree says that height is the best feature for splitting a certain group, but has various missing values for some observations. A surrogate split could be made with the next best predictor, such as weight, and can be used whenever the value for height is missing. The advantage of surrogate splits is that all observations can be used without having to guess the values of missing data. Because of this, surrogate splits will be used for this problem.</p><h4>Removing Outliers</h4><p>Outliers are <strong>observations whose features’ values deviate substantially from the rest of the observations.</strong> Although outliers are not common, they could severely impact our model’s performance. Luckily, outliers do not affect tree-based models too much since the split criteria is not substantially affected if an outlier is included in the training set. However, we will still remove extreme outliers for good practice and to potentially get rid of erroneous data. Since multivariate outlier removal can be a fairly complex subject, we will use an outlier technique that simply removes all of the data points that include a feature value that is <strong>greater than 3 standard deviations from that respective feature’s mean</strong>.</p><h4>Normalize or Standardize</h4><p>It is also important to mention that with many machine learning algorithms, <strong>normalization</strong> or <strong>standardization</strong> is utilized. Normalization is usually thought of as transforming the data so that it has a<strong> mean of 0 and a standard deviation of 1 </strong>whereas standardization generally implies transforming the data so that all of the data points lie between <strong>0 and 1</strong>. Luckily, these transformations are not needed for tree-based models since each split only depends on one feature rather than interactions with multiple features.</p><h3><strong>Feature Engineering</strong></h3><p>After the data is cleaned and processed, we will use feature engineering to create various features to be used in the model. The initial data types that will be used for the model are:</p><ul><li><strong>Data from both teams of the previous year: </strong>This includes results (such as the win rate, batting average, and points scored) for each game from the previous year that are then averaged.</li><li><strong>Data from both team from that same year: </strong>This includes the same results as before (win rate, batting average, and average points) except they will be averaged from previous games that <strong>same year</strong>.</li><li><strong>Odds of the game: </strong>These features will utilize the predictions from the bookmakers on how the game was going to go. For every game, the bookmaker gives odds for each team winning. These odds can then be converted to <strong>implied probabilities </strong>to show the chance a team has to win. <strong>If you’re curious to know a little more about odds and why they’re unfair, you can refer to my previous article written </strong><a href="https://nick-amir.medium.com/all-about-betting-odds-what-are-they-and-how-are-they-unfair-4f4d776582c3"><strong>here</strong></a>.</li></ul><h4>Binning</h4><p>Although binning was not used in this project, it is a common method of feature engineering. Binning takes continuous random variables and <strong>discretizes them into groups</strong> (turns them into categorical features). Binning usually bins features into groups with either a constant number of observations within each group or within groups that have a constant range. Binning can <strong>reduce training time and improve performance </strong>in some models.</p><h4>Manipulation of features</h4><p>Another form of feature engineering is<strong> manually manipulating features to make new features that seem like they could have predictive power</strong>. For example, the data from the previous year gives the total number of hits H from that year as well as the total number of runs scored R. A new feature would be to divide H by R to essentially get the hitting efficiency. This feature would show how many hits it would take to score a run on average. This form of feature engineering relies on knowledge about the subject at hand, so an expert in baseball could probably give more insight into other useful features.</p><h4>Moving Averages</h4><p>Another way to aggregate the data into features is to take a <strong>moving average of the data</strong> for the last couple games played and use those. For example, one of the pieces of data given is the total number of runs scored per game by each team. To implement this as a feature that I would use in a game for a specific team tomorrow, I could average the number of runs the team had in the last 5 games. This is a standard average, but other averages could be used as well (<strong>exponential, weighted, smoothed</strong>, etc.). The number of previous games to average is up to the user and an analysis of different numbers could be analyzed for optimization. This project uses a simple average of the previous 5 games for all of its same year features.</p><p>For all of these transformations, <strong>the difference between the home team’s values and the away team’s values are the features used</strong>. For instance, if the average number of runs scored last year was 7 for the home team and 5.6 for the away team, the feature used would be 1.4.</p><h3>Machine Learning Infrastructure</h3><h4>Initial Setup</h4><p>Now it comes time to actually create the model and apply machine learning. As mentioned, these previous steps usually take a majority of the time and are the more dry and monotonous portions, but now comes the fun. The steps used to create the model were:</p><ol><li><strong>Partition data into train/test splits</strong></li><li><strong>Determine which types of models will be tested</strong></li><li><strong>Initialize models with parameters</strong></li></ol><h4>1. Train/Test Split</h4><p>First, the training data must be partitioned into a <strong>training set and testing set</strong>. Sometime people also use a validation set, but we will use <strong>k-fold cross-validation</strong> as a substitution. <strong>With k-fold cross-validation, the training data is</strong> <strong>split up into separate folds in which each fold is used as a test set and the rest of the folds are used for a training set. This process is repeating until each fold has become a test set.</strong> The errors are then averaged out across each fold. It is important to note that throughout the entire model optimization process, the testing set should not be used until testing the very last model, or else we risk overfitting the test set. The training set will be 80% of the data and the test set will be the remaining 20%.</p><p>Usually, the data points that go into the training set and testing set is random, but we need to make sure that the data is <strong>stratified</strong>. This means that <strong>the target train and test sets have the same distribution</strong>. In our data, the targets are a 1 if the home team wins and a 0 if the home team loses. The mean value of our targets is 0.53, which means that the home team wins approximately 53% of the time. If we stratify our data, the targets for our training and test sets should each be comprised of about 53% ones and 47% zeros. If we didn’t stratify the data, we could get a distribution different in each class which could hinder our model’s performance for new observations.</p><h4><strong>2. Determine which types of models will be used</strong></h4><p>There are many different machine learning tree-based models we could use, so deciding on one is a difficult task. This is why we will simply try a couple of them and find the one with the highest accuracy. We will use a <strong>random forest</strong> model as well as <strong>various boosting models</strong>. We will also implement various tactics along the way to improve our models and analyze their performance. Before we do any optimizations, the models will all be tested with basic parameters to get a baseline of their performance.</p><h4><strong>3. Initialize models with parameters</strong></h4><p>The parameters used for each model are shown in Table 1. These are just the initial parameters used and will be optimized for each model over future steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hd6w0H8Ztt-KpmXUu00Ytg.png" /><figcaption>Table 1: Initial properties of various models trained</figcaption></figure><h3>Initial Results and Optimization</h3><h4>Confusion Matrix</h4><p>The first step in understanding our models is through the use of a <strong>confusion matrix</strong>. A confusion matrix <strong>finds how exactly the models made guesses and where their errors came from</strong>. There are 4 different types of predictions a model can make with respect to the targets:</p><ul><li><strong>True Positives:</strong> The<strong> </strong>model predicts a win and the home team actually wins</li><li><strong>True Negatives: </strong>The model predicts a loss the home team actually loses</li><li><strong>False Positives (Type I Error): </strong>The model predicts a win for the home team but they actually lose</li><li><strong>False Negatives (Type II Error): </strong>The model predicts a loss for the home team but they actually win</li></ul><p>Each model has its own confusion matrix containing the distributions of the 4 types of predictions listed above. For each matrix, the <strong>cross-validated results were used.</strong> A confusion matrix for one of the models, namely the Random Forest model, is shown in Figure 6. The results imply that the model was able to find some sort of patterns within the data since it is greater than just guessing. If we only bet when the model says a team is going to win, we would be correct 57.9% of the time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KUqOqFzxfGM2D-05ny8G4Q.png" /><figcaption>Figure 6: Confusion matrix for initial Random Forest model</figcaption></figure><h4>Implementing a cost matrix</h4><p>For our particular project, one strategy could be to bet on the home team only when our model predicts they will win. In this strategy, we would want to <strong>minimize the number of false positives</strong> since this would be bets made that ended up losing money. In other words, we want to maximize the probability that a prediction of the home team winning given by the model is correct. This value would be referred to as the<strong> positive predictive value (PPV)</strong>. PPV is <strong>how likely a positive prediction yields a positive result</strong>. In order to improve our PPV, we can implement a<strong> cost matrix.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*D0MP6v0Ugcn461QbKcoP7A.png" /><figcaption>Table 2: Default cost matrix</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*jAtHZQl1iM3PrU6BFgxKUw.png" /><figcaption>Table 3: Adjusted cost matrix</figcaption></figure><p>A standard cost matrix is shown in Table 2 and essentially shows the <strong>cost that each type of prediction would yield</strong>. If the model guesses correctly, the cost should obviously be zero. However, if the model guesses incorrectly, the various costs could be different depending on how the matrix is configured. Since we want to minimize false positives as much as possible, we want to set the cost higher for when the model predicts a win but the true result is a loss, shown in Table 3. Knowing exactly what to set this cost to requires trial and error and even differs depending on the model. Usually, I use a cost of around 1.1–1.5 and tweak it from there until I get a <strong>high enough PPV without sacrificing the number of positives being predicted</strong>.</p><h4>Misclassification Rate</h4><p>The next step in optimizing our models is to plot the accuracy vs the number of learners for each ensemble. We can <strong>look at the loss depending on the number of learners and find the optimal number of learners for each model</strong>. All of the comparisons only used cross-validated observation, with the exception of the random forest model which was also able to use the out-of-bag observations. Examples of the plots are shown in Figures 7 and 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K-CdKtZO1PZGfwkn_0Bsug.png" /><figcaption>Figure 7: Plot of the misclassification rate versus the number of learners for the Random Forest model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*__g5R826hw1NadVC6c92rA.png" /><figcaption>Figure 8: Plot of the misclassification rate versus the number of learners for the AdaBoost model</figcaption></figure><h4>Feature Importance</h4><p>Finally, we can examine which features were useful for the models.<strong> Too many features can lead to overfitting</strong> and therefore a low performance of the model. There are two methods that will be used, namely <strong>out-of-bag predictor importance by permutation and change in node impurity</strong>. The first method <strong>permutes a feature’s observations and then sums the errors of each tree using the out-of-bag samples.</strong> If the feature is important, then permuting the observations should have a largely negative impact on the performance of the decision tree since its values are randomized. Because this method requires bagged samples, it can only be used on models that bag observations, which in this case is only the Random Forest model. The second method looks at each split that used a particular feature and measures <strong>how well on average the feature did at improving the split</strong>. Since these algorithms are using Gini Impurity, the algorithms determine how well each feature minimized the Gini Impurity on the splits it was used on. This method does not require bagging and therefore is used on the rest of the models.</p><p>Examples of each type of feature importance are shown in Figures 9 and 10. First, we plot the importance for each model. Then, we<strong> find a threshold that a feature must reach in order to be used in the optimized version</strong>. For the Random Forest Model, a threshold of 0.2 was used and for the AdaBoost model, a threshold of 5E-5 was used.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOXB2UmmmHuzKnXe7PviCQ.png" /><figcaption>Figure 9: Feature importance for Random Forest model using OOB predictor permutation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XdQ2O0m6BsTQyYfDgPuXLQ.png" /><figcaption>Figure 10: Feature importance for AdaBoost model</figcaption></figure><h3>Final Results and Testing Betting Strategies</h3><p>Now that we have made adjustments to the models, we can retrain all of our models and keep repeating this process until we get a model that is to our liking. After optimizing our models and observing their results, the <strong>RUSBoost model had the highest performance</strong>. The confusion matrix for this model is shown in Figure 11. Although the results are not perfect, they provide an improvement over the original models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJFt7jJW4Dnm720S-us8mA.png" /><figcaption>Figure 11: Confusion matrix for RUSBoost model</figcaption></figure><h4>One Last Feature</h4><p>There is one last feature that will be added to the model. Our model is wrong around 40% of the time, but what if we could<strong> make another model to predict when the current one is wrong</strong>? Well, then we could use this as another feature in our model and it could potential be very useful. This idea is implemented using the same splits and optimizations strategies shown above. It is a useful strategy that can be applied to many different problems. The steps used to create this model are the same steps shown in the previous steps.</p><h4>Testing Betting Strategies</h4><p>So now we have a model that has seemingly good results, but how do we actually test this model to see if we could create a trading strategy with it? One potential strategy would be to only make bets on a team winning when the bookmaker says that team will team win <strong>in addition</strong> to a confidence threshold our model’s score must meet. Note, the model’s score is referring to the confidence our model gives to its prediction; this value’s range depends on the model. If the bookmaker says that a team will win with 60% probability, we might only bet if our model has a score of above 0.65, for example. We can <strong>test which score thresholds optimize the accuracies for each implied probability given by the bookmaker</strong> on our training set and test those results on our test set. The results are shown in Figure 12 for this method. Overall, with the exception of when the implied probability is 72%-75%, the score threshold <strong>improved the accuracy of the bookmaker’s model with an average increase in 9.2%</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zrLy9fxeVqlsKJBwO2TXcQ.png" /><figcaption>Figure 12: Change in accuracy of bookmaker’s model when adjusted with RUSBoost model</figcaption></figure><h3>Conclusion</h3><p>Albeit its results were not flawless, the RUSBoost model was able to improve upon the bookmaker’s model. The model is not tested specifically for profitability, but a 9% percent increase in accuracy is almost certainly enough to optimize a strategy to make consistent returns. If more time was spent on <strong>creating interesting features and gathering more data</strong>, the results could potentially even be better. The results could also be improved by using <strong>different boosting algorithms, such as XGBoost</strong>, or even different machine learning algorithms altogether.</p><p>What makes machine learning beautiful is that the state-of-the-art algorithms that the most advanced companies in the world are using can be<strong> improved with a little bit of ingenuity and creativity in modeling, free of charge in our office chairs.</strong></p><p>Thanks for reading this article! I hope you learned something and make sure to keep an eye out for future articles written — Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d349335b54" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beat-the-bookmakers-with-tree-based-machine-learning-algorithms-1d349335b54">Beat the Bookmakers With Tree-Based Machine Learning Algorithms</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[All About Betting Odds: What are they and how are they unfair?]]></title>
            <link>https://medium.com/analytics-vidhya/all-about-betting-odds-what-are-they-and-how-are-they-unfair-4f4d776582c3?source=rss-8bbc7723c8fb------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f4d776582c3</guid>
            <category><![CDATA[sports-betting]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[odd]]></category>
            <category><![CDATA[sports]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[Nicholas Amirsoleimani]]></dc:creator>
            <pubDate>Sun, 11 Apr 2021 02:49:27 GMT</pubDate>
            <atom:updated>2022-02-25T17:05:37.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPlFHGqv2CDXxGzSqJ8flQ.jpeg" /><figcaption><a href="https://morningconsult.com/2018/06/07/legal-sports-gamblings-future-younger-less-wealthy-bettors/">Source: Morning Consult</a></figcaption></figure><p><strong>– </strong><a href="#13e5"><strong>Introduction</strong></a><strong><br>– </strong><a href="#1020"><strong>Odds Conversion Table</strong></a><strong><br>– </strong><a href="#d61c"><strong>Various Odds Formats</strong></a><strong><br>– </strong><a href="#0252"><strong>Most Common Types of Bets</strong></a><strong><br>– </strong><a href="#1d7b"><strong>Why Sports Bets are NOT Fairly Priced</strong></a><strong><br>– </strong><a href="#1127"><strong>A More Rigorous Explanation</strong></a></p><h3>Introduction</h3><p>Sports alone are one of the most ubiquitous forms of entertainment that has existed throughout all of human history. The accompaniment of various forms of sports betting adds a new component to its already enjoyable nature. However, understanding these odds can sometimes be confusing and so this article was written in the hopes of clarifying this obscurity. In addition to this, we will discuss why these odds are priced unfairly and how the bookmaker is always expected to make a profit.</p><h3><strong>Odds Conversion Table</strong></h3><ul><li>To calculate the <strong>profit</strong> of a winning bet, <strong>multiply the bet size by the profit multiplier</strong>.</li><li>To get the <strong>total payout</strong>, <strong>add the</strong> <strong>total profit to the original bet size</strong>.</li><li>For example, if you make a $200 bet with -500 American odds and win, you would obtain a <strong>profit</strong> of $200*0.2=<strong>$40</strong> and a <strong>total payout</strong> of $40+$200=<strong>$240</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*haWzFNnoF7cyeic34BsnoA.png" /><figcaption>Odds conversion table</figcaption></figure><h3>Various Odds Formats</h3><h4><strong>American Odds</strong></h4><ul><li><strong>Examples:</strong> -200, +400, -1000, +2000</li><li><strong>Positive American Odds:</strong> If the American odds are <strong>positive</strong>, this bet represents the <strong>underdog</strong> and signifies <strong>how much money you will profit if you make a $100 bet</strong>. If you make a $100 bet with +400 American odds and end up winning, you will profit $400 and have a total payout of $500.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*uHnMU-X41nCKDCyxEbDMFQ.gif" /><figcaption>Profit for a bet made with positive odds</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*IbJfjDooK2AyNq1boxmg4w.gif" /><figcaption>Total Payout for a bet made with positive odds</figcaption></figure><ul><li><strong>Negative American Odds: </strong>If the American odds are <strong>negative</strong>, this bet represents the <strong>favorite</strong> and signifies <strong>how much money you need to wager in order to profit $100</strong>. If you make a $300 bet with -300 American odds and end up winning, you will profit $100 and have a total payout of $400.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*SpVXl_eb-8hG3AoaMEdFnw.gif" /><figcaption>Profit for a bet made with negative odds. The |Negative Odds| is the absolute value of the Negative Odds (Negative Odds without the minus sign).</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*gnikbiI0D1eBlJtzkX9gow.gif" /><figcaption>Total returns for a bet made with negative odds. The |Negative Odds| is the absolute value of the Negative Odds (Negative Odds without the minus sign).</figcaption></figure><h4><strong>Decimal Odds</strong></h4><ul><li><strong>Examples: </strong>1.5, 1.2, 2.5, 4.2</li><li>Decimal odds represent the <strong>total payout of a $1 bet. </strong>The <strong>total payout</strong> is comprised of the <strong>profit in addition to your original bet.</strong> If you bet $100 on 1.5 decimal odds and win, you will in total receive $150 but only profit $50.</li><li>If there are only two possible outcomes for a bet, the side with the <strong>higher decimal odds represents the underdog</strong> and the side with the <strong>lower decimal odds represents the favorite</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*HTVLIRb2mKXo-kE9sZ4PtA.gif" /><figcaption>Profit for a bet made with decimal odds</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*kvdHwEds6SEyFaBKSz7F3g.gif" /><figcaption>Total Payout for a bet made with decimal odds</figcaption></figure><h4><strong>Fractional Odds</strong></h4><ul><li><strong>Examples:</strong> 16/5, 13/10, 1/2, 2/1</li><li>Fractional odds represent the <strong>profit of a $1 bet. </strong>If you bet $100 on 13/10 decimal odds and win, you will profit $130 and receive a total payout of $230.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*k5HjgtoQoi3QS-qXFbhyrg.gif" /><figcaption>Profit for a bet made with fractional odds</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*qM0DnQqeMdbaGZSGrFZn1g.gif" /><figcaption>Total Payout for a bet made with fractional odds</figcaption></figure><h3>Most Common Types of Bets</h3><h4>MoneyLines</h4><p>This is simply a bet on <strong>which team will win the game.</strong></p><h4>Point Spreads</h4><p>A <strong>positive number</strong> indicates that this side is the <strong>underdog</strong> and needs to either <strong>win or lose by the corresponding point spread or less</strong>. A <strong>negative</strong> number indicates that this side is the <strong>favorite</strong> and needs to <strong>win by the corresponding points or more</strong>.</p><h4>Totals or Over/Under</h4><p>Totals is a bet type based on whether the <strong>sum of the points scored by both teams </strong>will be <strong>over</strong> <strong>or</strong> <strong>under</strong> a certain threshold. If the total number of points is equal to the totals threshold, this is usually referred to as a push and the original bet is given back to the bettors with no gain nor loss. Sometimes the over/under total ends in 0.5 so that a push cannot happen.</p><h4>Props</h4><p>Prop bets, short for proposition bets, are bets that <strong>can but do not have to be based on the outcome</strong> <strong>of the game</strong>. Almost all bets that are not moneylines, totals, or point spreads are classified as prop bets. These bets can range from which team is the first to score all the way to how many points is player X going to make.</p><h3>Why Sports Bets are NOT Fairly Priced</h3><p>First, let’s look at an example and review how these odds work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*8_OSXZHOt-M9dY7FI6DIEQ.png" /></figure><p>The home column shows the odds of betting on the home team whereas the away column shows the odds of betting on the away team for a specific bet. In this example, if you bet $100 on the home team and they win, you would win $110 (in addition to getting your original $100 back) and would lose your $100 if they lost. If you bet $130 on the away team and they win, you would win $100 (in addition to getting your original $100 back) and would lose your $130 if they lost. Since the returns are higher for the home team, they are less likely to win and therefore the underdog. Because of this, they are the underdog for the totals and need to either win or lose by at max 1 point whereas the away team needs to win by at least 2 points to get the payout for that bet. If the total number of points scored by both teams was above 8, a bet on the over would win whereas if the total number of points was below 8, a bet on the under would win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJEMKWCtfVFEtPJRR134CA.png" /><figcaption>Eq. (1): Relationship between returns and implied probability</figcaption></figure><p>Now, let’s explore a little deeper into these odds. How exactly do we convert these odds into returns (or profits) and how would we use these payouts to determine the probability of each team winning? If we look at the home odds for the moneyline, a $100 bet would yield $110 in returns. This is a return of $110/$100 = 1.1 = 110%. If we look at the away odds for the moneyline, a $130 bet would yield $100 in returns. This is a return of $100/$130 = 0.77 = 77%. Since the away team has <strong>smaller returns, they are more likely to win</strong>. But, how exactly do we quantify their chances of winning given their returns? Well, this chance is referred to as <strong>implied probability</strong> and is based on the returns of winning a made predicting a team’s success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LeK-iVElMr1KBlcpvF4PuQ.png" /><figcaption>Eq. (2): Relationship between implied probability and returns</figcaption></figure><p>The relationship in Eq. (2) shows the function to map the potential returns of a bet into the implied probability of winning that bet. <strong>Implied probability is the probability that would be needed to win a bet in order to fairly justify the returns given to winning said bet.</strong> If winning a bet would yield 40% in returns, for example, the implied probability of winning that bet would be roughly 71%. This makes relationship makes intuitive sense; if a team has a <strong>higher probability of winning</strong>, a bet placed on that team should <strong>yield lower returns</strong> since they are already expected to win and vice versa. Now, let’s use this information to understand the previous example a little more clearly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*rc1-zY_btbjHbV4zZl1uiw.png" /></figure><p>But, hold on. Why don’t these implied probabilities add up to 100%? Well, this is actually how the bookmakers make their money. <strong>The higher implied probabilities a team has, the lower payout a bet on them would be since they have a higher chance of winning.</strong> Therefore, if I’m the bookmaker and show that a team has a 65% chance to win when in reality they only have a 60% chance to win, I wouldn’t have to pay the winner as much since I am giving them an extra 5% chance to win. Therefore, the <strong>sum of the implied probabilities will ALWAYS exceed 100%</strong> . <strong>This is why sports odds</strong> <strong>are not fairly priced</strong> and the reason behind why <strong>bookmakers will always be expected to make money</strong>. The extent to which this sum exceeds 100% is known as overround, margin, or vig and varies from game to game, but always exist. This phenomenon also explains why a strategy to always bet on the favorite, or the underdog for that matter, would not have an expected return of $0; the expected returns would be negative.</p><h3>A More Rigorous Explanation</h3><p>Let’s explain this concept a little more symbolically. Imagine we are the bookmaker and wonder what our expected profit or loss would be given the returns we set for each team winning. This expected value is shown in Eq. (3). <strong>p_h and p_a are the <em>true </em>probabilities</strong> of the home team and away team winning respectively. In other words, if we have a model that predicts the home team will win with a probability of 60% and the away team will win with a probability of 40%, these would be p_h and p_a respectively.<strong> If the home team wins (which it will with probability p_h), we (the bookmaker) will win all of the money that was bet on the away team but lose the amount of money we have to pay out to the original bettors on the home team. </strong>The same but reverse payouts happens if the away team wins.</p><blockquote>Side note, since p_h and p_a are the true probabilities, they must add to 100%, or 1. This will be an important step later.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sBiwM_LTemRyL_gkiTgOAQ.png" /><figcaption>Eq. (3): Expected profit/loss in dollars from the bookmaker’s perspective</figcaption></figure><p>Next, let’s utilize the fact that <strong>we are going to inflate the true probabilities</strong> of each team winning and <strong>use these as our implied probabilities</strong>. Remember, the idea for doing this is because the higher probability we give a team to win, the less returns we have to payout to the winner (as shown in Eq. (2)). <strong>Altering the true probabilities ONLY changes the returns we have to pay out to the winner, not the actual probabilities of each side winning.</strong> If we do this and then replace those values in Eq. (2) and Eq. (3), we will obtain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J2nzDAuy8ojLyl_zd_PKSw.png" /><figcaption>Eq. (4): Expressing the returns the bookmaker has to payout as implied probabilities</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yGpy1pRbDT3lIHBYvXfayw.png" /><figcaption>Eq. (5): Substituting these returns back into Eq. (3)</figcaption></figure><p>Now, let’s determine exactly much we want to inflate the true probabilities. The <strong>amount we want to inflate these probabilitie</strong>s is decided by different <strong>deltas</strong>. When we express this and substitute this back into Eq. (5):</p><p>Now, let’s determine exactly much we want to inflate the true probabilities. The <strong>amount we want to inflate these probabilitie</strong>s is decided by different <strong>deltas</strong>. When we express this and substitute this back into Eq. (5):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uW7R4v9eYnRKBkzL66VxNg.png" /><figcaption>Eq. (6): Expressing implied probabilities as a sum of the true probabilities, p*, and some surplus, deltas</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHn2jG_9ORtRp9LD8DdK1g.png" /><figcaption>Eq. (7–13): Substituting Eq. (6) into Eq. (5) and simplifying. Note that in Eq. (11), the sum of the true probabilities disappeared since it equals 1.</figcaption></figure><p><strong>The expected profit/loss for the bookmaker is the weighted sum of the money bet on the home team and the money bet on the away team, where the weights are equal to the degree to which we inflate the true probabilities.</strong> Notice that since both deltas must be positive, the bookmakers expect to see a profit. This profit multiplied by thousands of bets is how the bookmakers make money and why the odds are not fairly priced.</p><p>Thanks for reading this article! I hope you learned something and make sure to keep an eye out for future articles written — Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f4d776582c3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/all-about-betting-odds-what-are-they-and-how-are-they-unfair-4f4d776582c3">All About Betting Odds: What are they and how are they unfair?</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>