<?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 Amin Azad on Medium]]></title>
        <description><![CDATA[Stories by Amin Azad on Medium]]></description>
        <link>https://medium.com/@amindazad?source=rss-cf1382641795------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*e8Vb6GtLRTGJ4EwAUqBEIQ.jpeg</url>
            <title>Stories by Amin Azad on Medium</title>
            <link>https://medium.com/@amindazad?source=rss-cf1382641795------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:42:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amindazad/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[Classification Model from Scratch]]></title>
            <link>https://medium.com/data-science/classification-model-from-scratch-49f24bdd0636?source=rss-cf1382641795------2</link>
            <guid isPermaLink="false">https://medium.com/p/49f24bdd0636</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Amin Azad]]></dc:creator>
            <pubDate>Fri, 31 Jul 2020 00:18:28 GMT</pubDate>
            <atom:updated>2020-09-15T19:11:50.880Z</atom:updated>
            <content:encoded><![CDATA[<h4>Beginner’s guider in building a Naive Bayes Classification Model (simple classification model) from scratch using Python.</h4><h4><a href="https://github.com/amindazad/Naive_Bayes_Classifier">Github Repository</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dn8o5YtS4QjYMRam4BQ9fg.gif" /><figcaption><a href="https://dribbble.com/shots/2194312-Hello-World">CAMERON FOXLY “BASIC programming into an old computer”</a></figcaption></figure><p>In machine learning, we can use probability to make predictions. Perhaps the most widely used example is called the Naive Bayes algorithm. Not only it is straightforward to understand, but it also achieves surprisingly good results on a wide range of problems.</p><p>Naive Bayes algorithm is a classification technique based on the Bayes Theorem. It assumes that a feature in a class is unrelated to the presence of any other feature. As shown in the following formula, the algorithm relies on the posterior probability of the class given a predictor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*_sBK3LWI7jp3zoqE4PS97g.png" /></figure><p>where:</p><ul><li><strong>P(c|x)</strong> is le postérieur probability of classe given a predictor</li><li><strong>P(x|c) </strong>is the probability of the predictor given la classe. Also known as Likelihood</li><li><strong>P(c) </strong>is the prior probabilité of the class</li><li><strong>P(x) </strong>is the prior probabilité of predictor.</li></ul><p>Or in plain english, the Naive Bayes classifier equation can be written as :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*3BCMTbQ-i7AKd_cFxAQbkA.png" /></figure><p>The good news is Naive Bayes classifier is easy to implement and performs well, even with a small training data set. It is one of the best fast solutions when it comes to predicting the class of the data. <a href="https://scikit-learn.org/stable/modules/naive_bayes.html">Scikit-learn</a> offers different algorithms for various types of problems. One of them is the <strong>Gaussian Naive Bayes</strong>. It is used when the features are continuous variables, and it assumes that the features follow a Gaussian distribution. Let’s dig deeper and build our own Naive Bayes classifier from scratch using Python.</p><h3>1. Load required libraries</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f5352c7897db91ad1ae8bf924d514e6/href">https://medium.com/media/2f5352c7897db91ad1ae8bf924d514e6/href</a></iframe><p>The only required library to build your own Naive Bayes classifier is <a href="https://numpy.org/">NumPy</a>. NumPy is an open source project aiming to enable numerical computing with Python and we would use it for arithmetical operations.</p><h3>2. Instantiate the class</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a65c1b736612c2441287950b5c7b153/href">https://medium.com/media/4a65c1b736612c2441287950b5c7b153/href</a></iframe><p>The next step is to instantiate our Naive Bayes classifier class. A Class is like an object constructor, or a “blueprint” for creating objects. In an object oriented programming language, almost everything is an object, with its properties and methods.</p><p>“__init__” is a reserve method in python classes. It is known as a constructor in object oriented concepts. This method is called when an object is created from the class and it allows the class to initialize the attributes of a class.</p><h3>3. Separate Classes</h3><p>According to the Bayes Theorem, we need to know the prior probability of any class before attempting to predict that particular class. To calculate this, we have to assign the feature values to the specific class. We can do this by separating the classes and saving them into a dictionary.</p><p>Dictionaries are Python’s implementation of a data structure that is more generally known as an associative array. A dictionary consists of a collection of key-value pairs. Each key-value pair maps the key to its associated value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c00518a6d1bf92664942705d0906fd2e/href">https://medium.com/media/c00518a6d1bf92664942705d0906fd2e/href</a></iframe><h3>4. Feature Summary (Statistics info)</h3><p>The likelihood, or the probability of predictor given the class, is assumed to be normally distributed (<a href="https://en.wikipedia.org/wiki/Gaussian_function">Gaussian</a>) and is calculated based on mean and standard deviation <em>(see formula)</em>. We’re going to create a summary for each feature in the data set, doing this would make it easier for us to access mean and standard deviation of features in the future.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bea246dacdc55c77b4fa9478f15751d4/href">https://medium.com/media/bea246dacdc55c77b4fa9478f15751d4/href</a></iframe><ul><li>The zip() function here is an iterator of tuples where the values are paired together for each feature. In Python, tuples are compound data types which are immutable.</li><li>We choose to yield because we want to produce a sequence of values over which we will iterate later on, without explicitly saving the sequence in memory.</li></ul><h3>5. Gaussian distribution function</h3><p>The likelihood for features following a normal distribution is calculated using the Gaussian distribution function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*bm3Ga_syxriFXwTLB8EsVg.png" /></figure><p>To use the formula for further calculation we defined a distribution method and embedded the formula exactly as it exist above.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c9aa0222aa5dab590f81cba258781fd3/href">https://medium.com/media/c9aa0222aa5dab590f81cba258781fd3/href</a></iframe><h3>6. Train the model</h3><p>Training the model means applying the model to the dataset so it can iterate through the data set and learn dataset’s patterns. In the Naive Bayes classifier, training involves calculating the mean and standard deviation for each feature of each class. This will allow us to calculate the likelihoods to be used for predictions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a42f4a6381040ed08bd2d6926061b978/href">https://medium.com/media/a42f4a6381040ed08bd2d6926061b978/href</a></iframe><p>If we take a closer look to the code snippet above, we can see that we have separated the classes in the training data set. Then, calculated the mean and standard deviation for each class and then calculated the prior probability of the class using len(feature_values)/len(X).</p><h3>7. Predict</h3><p>To predict a class, we have to first calculate the posterior probability for each class. The class with the highest posterior probability will be the predicted class.</p><p>The posterior probability is the joint probability divided by the marginal probability. The marginal probability, or the denominator, is the total joint probability of all classes and will be the same across all classes. We need the class with the highest posterior probability, which means it will be the greatest joint probability.</p><h4><strong>Joint probability</strong></h4><p>Joint probability is the numerator of the fraction used to calculate the posterior probability. For multiple features, the joint probability formula is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*duSMQO8fhSpyiWzD8-K4jg.png" /></figure><p>Applying the same formula using Python would result to the following code snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ef1322814b700dc6a6f8c8b8743b7d5/href">https://medium.com/media/3ef1322814b700dc6a6f8c8b8743b7d5/href</a></iframe><p>Taking a closer look at the snippet above, we followed the following steps for each class:</p><ul><li>Get the summary (mean, standard deviation, and prior probability)</li><li>Calculate the Normal Probability of each feature</li><li>Get the total likelihood (the product of all normal probabilities)</li><li>Get the joint probability by multiplying the prior probability with the total likelihood.</li></ul><h4><strong>Predict the class</strong></h4><p>After having the joint probability of each class, we can select the class with the maximum value for the joint probability:</p><p>max(joint_proba, key=joint_proba.get)</p><h4><strong>Putting it all together</strong></h4><p>If we put the joint probability step and predict class step together, we can predict the class for each row in a test data set with the following code snippet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/864fdbe346b1d8fe8e4c81c276f5ae43/href">https://medium.com/media/864fdbe346b1d8fe8e4c81c276f5ae43/href</a></iframe><h3>8. Accuracy Score</h3><p>Calculating the accuracy score is an essential part of testing any machine learning model. To test our Naive Bayes classifier’s performance, we divide the number of correct predictions by the total number of predictions which would give us a number from 0 to 1.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/417d8ef031edad2b397c39937d3b5e29/href">https://medium.com/media/417d8ef031edad2b397c39937d3b5e29/href</a></iframe><h3>Our NaiveBayesClassifier vs. Sklearn GaussianNB</h3><p>Now that we built our classification model, let’s use the <a href="https://archive.ics.uci.edu/ml/datasets/Wine">UCI Wine data set</a> to compare our model’s performance with the performance of the GaussianNB model from scikit-learn.</p><h4>Naive Bayes Classifier</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8bf109fd23143d74181f6eb98e4aaac/href">https://medium.com/media/b8bf109fd23143d74181f6eb98e4aaac/href</a></iframe><p>NaiveBayesClassifier accuracy: <strong>0.972</strong></p><h4>Sklearn Gaussian NB (Naive Bayes)</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/154459e5d6df26002a0055303b3fef93/href">https://medium.com/media/154459e5d6df26002a0055303b3fef93/href</a></iframe><p>Scikit-learn GaussianNB accuracy: <strong>0.972</strong></p><p>As you can see, the accuracy of the models is the same, meaning that we implemented a successful Gaussian Naive Bayes model from scratch.</p><p>Feel free to use the <a href="https://github.com/amindazad/Naive_Bayes_Classifier">github repository here</a> to find the entire python files and the notebook used to create this article.</p><h3>References</h3><p><a href="https://dataaspirant.com/2017/02/06/naive-bayes-classifier-machine-learning/">How The Naive Bayes Classifier Works In Machine Learning</a></p><p><a href="https://archive.ics.uci.edu/ml/datasets/Wine">UCI Wine Data Set</a></p><p><a href="https://scikit-learn.org/stable/modules/naive_bayes.html">Scikit-learn Naive Bayes</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49f24bdd0636" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/classification-model-from-scratch-49f24bdd0636">Classification Model from Scratch</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Twitter Topic Modeling]]></title>
            <link>https://medium.com/data-science/twitter-topic-modeling-e0e3315b12e2?source=rss-cf1382641795------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0e3315b12e2</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[lda]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <dc:creator><![CDATA[Amin Azad]]></dc:creator>
            <pubDate>Mon, 13 Jul 2020 03:35:15 GMT</pubDate>
            <atom:updated>2020-07-13T04:25:09.021Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QdluAy2mkaDv0shOiOK5gw.jpeg" /><figcaption><a href="https://unsplash.com/photos/V6CdmV277nY">Morning Brew Unsplash Channel</a></figcaption></figure><h4>Using Machine Learning (<a href="https://radimrehurek.com/gensim/models/ldamodel.html">Gensim Linear Discriminant Analysis</a> — LDA) to explore what topics your followers are engaging with the most.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U67CHl7gx_-WUy4LS89TAw.gif" /><figcaption>From LDA base model to model 6.3 after 24 rounds of hyper-parameter tuning</figcaption></figure><p>I’m a machine learning geek and I’d like to apply machine learning on everything that I can just to see the results. On the other hand, I started a new role at <a href="https://www.so-me.net/">SoMe (Social Media Management Platform)</a> and within the data science team, we continuously brainstorm around using machine learning to create more value for our users and help them grow their follower base. We thought long and hard to come up with the best ideas, and in the process, we realized the first step is to provide the user with an overall understanding of their follower base.</p><p>There is a wide range of data science and machine learning techniques that could be applied for providing a better understanding of your followers, from applying CNN (Convolutional Neural Networks) on Instagram to applying natural language processing techniques on Twitter, Linkedin or any other text-based data. Majority of our users use <a href="https://www.so-me.net/">SoMe</a> to sort and schedule their future posts on Twitter so as a first step we decided to provide our users with insights about the topics their Twitter followers engage with the most. To do that we first had to define and score follower engagement. After a long discussion, we defined and scored follower engagement as “When a follower interacts with the content that user posts by 1. Retweeting (5/5) — 2. Retweeting with a comment (4/5) — 3. Liking (3/5) —4. Comment(2/5) — 5. Mentioning (1/5)”.</p><p>Next step was to actually get the data from a Twitter api, I will write about applying for a Twitter api and using <a href="https://www.tweepy.org/">Tweepy</a> and other tools to pull data and refine data to get to the data you need from the api in a future post. You can use the following techniques on any kind of text data and figure out what are the most important topics discussed within your dataset.</p><h3>Load required packages</h3><p>Depending on your choice of python notebook, you are going to need to install and load the following packages to perform topic modeling. Among the SoMe, data science team we use a wide range of notebook options, from Azure to Jupyter labs and notebook. My personal favorite however is <a href="https://colab.research.google.com/notebooks/intro.ipynb">Google Colab</a>. I recommend running all the following snippets on either Google Colab or Jupyter notebook. I’m also going to link the Github repository for this project and a link to the final notebook we used for your reference.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba4d0fe809d8a7756a0b433d25ce0586/href">https://medium.com/media/ba4d0fe809d8a7756a0b433d25ce0586/href</a></iframe><h3>Data Cleaning</h3><p>After pulling and refining the data from the Twitter api and importing the required packages, we had to clean the data from emojis and urls so we can tokenize it for the next steps. You can find the cleaning syntaxes we used in the below snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/407e897b462f40832521eb9fe6d0caaf/href">https://medium.com/media/407e897b462f40832521eb9fe6d0caaf/href</a></iframe><p>As you can see in the table below, there are a lot of emojis and urls you want to remove before tokenizing. Data cleaning is essential for ultimately delivering accurate results, we do not want words from websites or emojis end up in our topic modeling results since they deliver almost no value in figuring out what is the general topic of a bag of words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F0QUYASWtnjLgb_u9PuaMA.png" /></figure><h3>Data Pre-processing</h3><p>Our goal in the data pre-processing stage is to convert sentences into words, convert words to their root and removing words that are too common or too irrelevant to the purpose of our topic modeling project. We used the following techniques to reach our goal, I’m going to share the code and walk you through each stage:</p><ul><li><strong>Tokenization</strong>: Split the text into sentences and the sentences into words. Lowercase the words and remove punctuation.</li><li>Words that have fewer than 3 characters are removed.</li><li>All <strong>stopwords</strong> are removed.</li><li>Words are <strong>lemmatized</strong> and stemmed — words in the third person are changed to first person and verbs in past and future tenses are changed into the present and are reduced to their root form.</li></ul><h4>Tokenizing</h4><p>Tokenization<strong> </strong>is always the first step before we can do any text data processing. What this means is that spaCy will segment sentences into words, punctuations, symbols and others by applying specific rules to each language. Spacy is a pre-trained natural language processing model capable of figuring out the relationship between words. You can learn more about Spacy <a href="https://towardsdatascience.com/so-whats-spacy-ad65aa1949e0">here</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f3a803eb320928a91915c1803ab4383/href">https://medium.com/media/2f3a803eb320928a91915c1803ab4383/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJhYskgYgpxRfn-mL2ODGg.png" /></figure><h3>Lemmatization</h3><p>Lemmatization is a process where we convert words to its root word. For example: ‘Studying’ becomes ‘Study’, ‘Meeting becomes ‘Meet’, ‘Better’ and ‘Best’ become ‘Good’.The advantage of this is, we get to reduce the total number of unique words in the dictionary. As a result, the number of columns in the document-word matrix will be denser with lesser columns. The ultimate goal of lemmatization is to help the LDA model to produce better topics in the end.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dcb90ded11b48195c935cf6c72d4a40/href">https://medium.com/media/6dcb90ded11b48195c935cf6c72d4a40/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UyWF6wVJlSbVDHhIYXw-Fw.png" /></figure><h3>Topic Modeling</h3><h4>Base Model</h4><p>We produce a base model first to be used to track our progress as we go through the hyper-parameter tuning stage. The LDA topic model algorithm requires a document word matrix and a dictionary as the main inputs. For the first few steps to be taken before running the LDA model, we created a dictionary, filtered the extremes and, create a corpus object which is the document matrix LDA model needs as the main input.</p><p>We prepared everything required to train the LDA model. In addition to the corpus and dictionary, we needed to provide the number of topics as well. We chose 5 for the base model. In the hyperparameter tuning stage we will reach to an optimum number of topics to be used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4118283ff5ac22a5e2f7e8c1e3c2811f/href">https://medium.com/media/4118283ff5ac22a5e2f7e8c1e3c2811f/href</a></iframe><p>By printing out the topics produced from the LDA model, we can have a rough guess about the topic related to each bag of words. It’s important to mention the bag of words have been sorted from the most relevant to the least relevant for each topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*v0slaRm0qkCSJ0bfrHCxJg.png" /></figure><p>Model perplexity and <a href="https://rare-technologies.com/what-is-topic-coherence/">topic coherence</a> provide a convenient measure to judge how good a given topic model is. In my experience, topic coherence score, in particular, has been more helpful.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37ff5d69bd5f1de11216011b29b6bb1f/href">https://medium.com/media/37ff5d69bd5f1de11216011b29b6bb1f/href</a></iframe><p>We got 0.17 for coherence score, which is a very low score for almost any LDA model but remember this is only the base model, we are going to substantially improve it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*FWHMrrL9ZbrpCoYl3x-o1w.png" /></figure><p>Now that the LDA model is built, the next step is to examine the produced topics and the associated keywords. There is no better tool than pyLDAvis package’s interactive chart and is designed to work well with Google Colab and Jupyter notebooks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9a6b07390b07cc62eac2bd303b940bf/href">https://medium.com/media/e9a6b07390b07cc62eac2bd303b940bf/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eZbawGyiLYYXpA2dTScUeg.png" /></figure><p>So how to infer pyLDAvis’s output?</p><p>Each bubble on the left-hand side plot represents a topic. The larger the bubble, the more prevalent is that topic. A good topic model will have fairly big, non-overlapping bubbles scattered throughout the chart instead of being clustered in one quadrant. A model with too many topics, will typically have many overlaps, small sized bubbles clustered in one region of the chart.</p><p>Alright, if we move the cursor over one of the bubbles, the words and bars on the right-hand side will update. These words are the salient keywords that form the selected topic. We have successfully built a good looking topic model. Up next, we will improve upon this model (Hyperparameter Tuning) by using <a href="https://scikit-learn.org/stable/index.html">Scikit-learn’s </a>Grid Search and then we will focus on how to arrive at the optimal number of topics and other variables in within the LDA model.</p><h3>Hyperparameter Tuning</h3><h4>Grid Search</h4><p>The most important tuning parameter for LDA models is n_components (number of topics). In addition, we are going to search learning_decay (which controls the learning rate) as well. Besides these, other possible search params could be learning_offset (down weight early iterations. Should be &gt; 1) and max_iter. These could be worth experimenting if you have enough time and computing resources.</p><p>Be warned, the grid search constructs multiple LDA models for all possible combinations of param values in the param_grid dict. So, this process can consume a lot of time and resources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73116135f8fad997179cf274365ccd8b/href">https://medium.com/media/73116135f8fad997179cf274365ccd8b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*Ks53lO_i73kiy9YWqi1G1Q.png" /></figure><p>We know there is a high chance number of topics is much more than 10 but through the grid search we found out 10 topics performs better than other number of topics. This makes us think deeply about the results, and we figured Scikit-learn’s grid search tracks perplexity not coherence value and for our use case, coherence value delivers the best result. In the next step we’re going to get to an optimal number of topics.</p><h4>Optimum number of topics</h4><p>Our approach to finding the optimal number of topics was to build many LDA models with different values of number of topics and pick the one that gives the highest coherence value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eede3a6fc32ef3e3e331ee5ad7e2e9ec/href">https://medium.com/media/eede3a6fc32ef3e3e331ee5ad7e2e9ec/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F1.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F1%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/578a1776f17d83c4a5379150a7a0e7cd/href">https://medium.com/media/578a1776f17d83c4a5379150a7a0e7cd/href</a></iframe><p>Choosing a number of topic that marks the end of a rapid growth of topic coherence usually offers meaningful and interpretable topics. Picking an even higher value can sometimes provide more granular sub-topics.If you see the same keywords being repeated in multiple topics, it’s probably a sign that the ‘number of topics’ is too large. By following these principles we chose 68 topics as an optimal number of topics for our use case.</p><h4>Optimal Number of Passes</h4><p>Passes, chunksize and update_every are parameters that have a EM/Variational relationship together. We are not going to go into the details of EM/Variational Bayes here, but if you are curious, check out this <a href="https://groups.google.com/forum/#!topic/gensim/z0wG3cojywM">google forum post</a> and the paper it references <a href="https://www.google.com/url?q=https%3A%2F%2Fwww.cs.princeton.edu%2F~blei%2Fpapers%2FHoffmanBleiBach2010b.pdf&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNEqb96J5aHxeTva_s_ieCKGzOBbDA">here</a>. For our use case, hyperparameter tuning number of passes would suffice considering chuncksize is not substantial and update_every would not change much in the final results.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F9.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F9%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e002cb8c90dd78a13a0827acebfd9e0/href">https://medium.com/media/8e002cb8c90dd78a13a0827acebfd9e0/href</a></iframe><p>We tried many numbers of passes and 20 seems to produce the best result. Not substantially though, only a few decimal points.</p><h4>Alpha Type</h4><p>Alpha is the hyperparameter for the Dirichlet prior. The Dirichlet prior is the distribution from which we draw theta. And theta becomes the parameter that decides what shape the topic distribution is. So essentially, alpha influences how we draw topic distributions. That is why we’re gonna try to hyperparameter tune to choose the best alpha type that gives you a better topic distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ykhofQMLkT-Js_ivRYRcUw.png" /></figure><p>In our use case, symmetric alpha delivers a better result, not substantially but we are going to use symmetric alpha for our LDA model.</p><h4>Decay</h4><p>Learning decay controls the learning rate of the model. Since you can only choose 0.5, 0.7 and 0.9, we’re going to try all three and see which option delivers the best coherence value.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F11.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F11%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/89622f040b6088b290733b85f9b4457d/href">https://medium.com/media/89622f040b6088b290733b85f9b4457d/href</a></iframe><p>In our use case, 0.5 decay delivers the best coherence value. In fact, decay and coherence value in our use case seems to be negatively correlated.</p><h4>Optimal number of iterations</h4><p>iterations is somewhat technical, but essentially it controls how often we repeat a particular loop over each document. It is important to set the number of “iterations” high enough.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F13.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F13%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/241fd705c9bc4af18c2df2ccaea1c1ba/href">https://medium.com/media/241fd705c9bc4af18c2df2ccaea1c1ba/href</a></iframe><p>In our use case, we tried 50 to 100 iterations but since we want to prevent the model from overfitting we chose 70 which showed a decent amount of coherence score improvement.</p><h4>Minimum Probability</h4><p>This hyperparameter disregards topics with probability assigned lower than what is assigned. It can not be lower than 0.01 and higher than 0.1.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F16.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F16%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee56e6d791ac9823968959e7919171d1/href">https://medium.com/media/ee56e6d791ac9823968959e7919171d1/href</a></iframe><p>We tried the full range of 0.01 to 0.1 and coherence value remained constant across the full range so we left it to the default value of 0.01 to get the most amount of topics possible.</p><h4>Progress Track Sheet</h4><p>It is always a good practice to track your progress from the beginning. We have been tracking our progress going through 24 iterations of model hyperparameter tuning and our best model delivers a coherence value of 0.47 which is a pretty good number considering the wide range of topics that could be discussed among users follower base.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F25.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F25%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/51a8ff5889606b675c81b08f12fa5a12/href">https://medium.com/media/51a8ff5889606b675c81b08f12fa5a12/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplotly.com%2F%7Eso-me%2F27.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fchart-studio.plotly.com%2F%7Eso-me%2F27%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plotly" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/491ff149a1c684541a50a47076f3e10f/href">https://medium.com/media/491ff149a1c684541a50a47076f3e10f/href</a></iframe><h3>Final Model &amp; Results</h3><p>We finally got to our final model. We’re currently using the model in the snippet below at <a href="https://www.so-me.net/">SoMe</a> to provide our users with the topics their followers interact with the most.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3de80f2ce13cadc409b3620cc01ea61b/href">https://medium.com/media/3de80f2ce13cadc409b3620cc01ea61b/href</a></iframe><p>If we take a closer look at the topics produced by the final model, we can guess with a high accuracy what each topic is about. Now we have to remember they are sorted from the highest importance to the least. For example, if we look at Topic one we figure it&#39;s about the COVID-19 crisis as the first three words are “die-virus-lockdown” and not so much about “gold” since “gold” is the fourth word which does not reflect a high probability in the bag of words.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKM3vQnxF0BuDKeLN9UxNw.png" /></figure><p>As we covered before, a good topic model will have non-overlapping, fairly big sized blobs for each topic and if we increase number of topics based on the use case we’re going to have smaller blobs and some overlap in some cases but overall we can see in the final model, the distribution and overlap have significantly improved. This seems to be the case here. So, we are good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKOhxK29XVRBML6-k_exDw.png" /></figure><h3>Conclusion</h3><p>We’ve covered some cutting-edge topic modeling approaches in this post. We continuously work to build new features for our users and harness machine learning’s power to provide a better experience for our users. To improve this model you can explore modifying it by using <a href="https://radimrehurek.com/gensim/models/wrappers/ldamallet.html">gensim LDA Mallet</a> which in some cases provides more accurate results. For those concerned about the time, memory consumption and variety of topics when building topic models check out the <a href="https://www.machinelearningplus.com/nlp/topic-modeling-gensim-python/">gensim tutorial on LDA</a>.</p><p>At the end, I have to thank the rest of SoMe data science team especially <a href="https://www.linkedin.com/in/jacobpadgett/">Jacob Padgett</a> and <a href="https://www.linkedin.com/in/lawrence-kimsey/">Lawrence Kimsey</a>. At SoMe, we strongly believe in open source software and you can find all our analytics models notebooks <a href="https://github.com/some-labs-24/data-science">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0e3315b12e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/twitter-topic-modeling-e0e3315b12e2">Twitter Topic Modeling</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let Data Improve Your Tennis Game]]></title>
            <link>https://medium.com/data-science/let-data-improve-your-tennis-game-37f346377663?source=rss-cf1382641795------2</link>
            <guid isPermaLink="false">https://medium.com/p/37f346377663</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[tennis]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Amin Azad]]></dc:creator>
            <pubDate>Fri, 06 Mar 2020 19:32:06 GMT</pubDate>
            <atom:updated>2020-07-08T23:46:29.443Z</atom:updated>
            <content:encoded><![CDATA[<h4>How machine learning models could be used to improve chances of one player winning the game by building a more effective game strategy based on the most important metrics extracted from data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhCHWUWA9MmYowNgxRNALA.jpeg" /><figcaption><a href="https://www.esri.com/arcgis-blog/wp-content/uploads/2012/09/TennisData.jpg?rmedium=bulk-arcgis-files&amp;rsource=http://blogs.esri.com/esri/arcgis/files/2012/09/TennisData.jpg">DAMIEN SAUNDER, ESRI “data dump” all of the bounces and racket strikes of every ball in the 2012 Olympic gold medal match between Roger Federer and Andy Murray.</a></figcaption></figure><p>I’m a tennis geek. I like to play tennis, watch tennis and even play fantasy tennis every week. Although fantasy tennis is not as widespread as fantasy football there are a fair amount of people participating in it around the world. There are a variety of formats but the most common one is the bracket. In the bracket format the fantasy tennis player tries to predict who will be the winner of all tennis matches in a tournament. I also play tennis a lot and since childhood I always wondered if I can improve my game by focusing on parts of the game that are more important, I tried to ask many people’s opinion about the most important skills in the game but to no answer was convincing enough for me. Fortunately I found match data of almost 6000 decided to see if data could improve not only my game but also improve my winning chances during the game.</p><h3><strong>Dataset</strong></h3><p>Dataset was collected from ATP’s website and the initial format included nearly all ATP matches from 1968 through part of 2018. The data includes a number of interesting features, such as the player rankings, the number of points accumulated at the time of the match, in match statistics, number of aces each player hit during the match, player service and return ratings, etc. Unfortunately, there are a number of features the data did not include, such as forehand statistics, and, a number of the early observations did not include all of the features. I decided to cut the data short and delete all pre 2000 matches from the data for two main reasons, first the nature of the game and format of ATP games changed from the year 2000 and second to save time since the data was too big and it was taking too much time to be processed on my local computer or on Google Colab.</p><p>All the datasets used and the predictive modeling notebook could be found <a href="https://github.com/amindazad/ATP_ITF_TennisMatch_Winner">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F55.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F55%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/905fd86be2aee61eb6333aaa82f41b03/href">https://medium.com/media/905fd86be2aee61eb6333aaa82f41b03/href</a></iframe><h3>Data Cleaning</h3><p>The first step in the preprocessing was to deal with columns with null and zero values and then combine all the individual datasets into one big dataset. Since all the datasets contained some of the same features, this was straightforward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Evk9gpLOYt7b-QI6WMXJVQ.png" /><figcaption>Figure 2 : Pandas Profiling report of some of the columns with missing values or high cardinality</figcaption></figure><p>The second step was to remove the leakage and some biases in the dataset. Since the original data labelled all the data with the column names “total points won” and “sets won”, depending on whether the data belonged to the winning player or the losing player, it was necessary to remove some of the columns to prevent leakage and also relabel some of the relevant columns to avoid the bias that might result when using the data to build our model. To do so, I randomly assigned player1 to either the winner or loser, and player2 to the other player. The random assignment resulted in player1 as the winner around half the time.</p><p>The third step was to filter the dataset to avoid zero or null values and to only include those observations where the ranking of both players was available, since I intuited that this would be the strongest predictor. This reduced the number of observations from around 10k to around 6k. Although this was a dramatic reduction, it turns out that most of the discarded data lacked significant information anyway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*74egaMwvnu0LGQ37ul9Meg.png" /><figcaption>Figure 3 : Null values from some of the columns. It turned out during those years they were not recorded</figcaption></figure><h3>Feature Engineering</h3><p>Some prior machine learning models used only the ranking of the two players to predict match outcome. This makes sense, since the ranking captures a players performance over the past year, and is likely a strong predictor of the player’s current ability to win against a poorly rated player. However, there are many other types of information that might be useful in predicting the outcome of a match, and in some instances they could be used to predict the match results in live format. For example, the past head to head of two players could be extremely relevant, especially the most recent matches, or after deploying my model I found out winning the first set is a strong indicator of the match result. The quality of a player’s service game and return game is also likely of importance.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F53.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F53%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/48cc816f658901ff8cc0a070a8f8a005/href">https://medium.com/media/48cc816f658901ff8cc0a070a8f8a005/href</a></iframe><p>To better capture the nuances of each player, I decided to compute the past head to head of each player for each match, and service metrics (service / return scores) from past matches for both players. These data were only available post 1991. To ensure that enough data was available in the past, I decided to further restrict the dataset to matches post 2000. That way, I would have about 19 years of past match data to compute these statistics.</p><p>The features I computed included: aces per point, double faults per point, head to head results between the two players, first serve percentage, second serve percentage, etc. I scaled the serve data by point to avoid the bias that would occur if, for example, I had used number of aces, since a player may have had more opportunities to hit an ace than his opponent. One issue that arose is that some observations included new players, for which there was no prior record of performance. One option was to label all statistics for this player as 0, but that would likely produce biased results, since 0 is the lowest metric, and just because a player has no prior matches in the record, does not mean that he should be assigned the worst score. I ultimately decided to delete all observations with 0s in them, which does not seem like the best solution. This is something to look into in the future.</p><p>Finally, most modeling in the past combined the player 1 feature and the player 2 feature into a single feature. For example, for the ranking feature, subtracting the two rankings would consolidate the two features into a single feature. This has the advantage of producing a symmetric model and reducing the feature space by half. However, it has the disadvantage of eliminating information. I decided to not consolidate any of the features into a single feature.</p><h3>Predictive Modeling</h3><p>Since this is a classification problem (Player victory = True/False). To test the models, I first split the data into a 80% — 20% train test split and I used cross validation with grid search to select the best hyper parameters, refit the best hyper parameters to the full train set, and tested the model on the validations and test set through a 5 fold cross validation.</p><p>The baseline for this problem was the majority class accuracy score of 0.51, meaning just by guessing we could predict a player won the match 51% of the time. I used variety of linear and tree based models such as logistic regression, single decision tree (to find leakage), random forrest and XGboost to predict the winner. XGboost out performed the other models by ~1% in which the outcome came to be a validation accuracy of 96%.</p><p>I then used permutation importances to find which features are contributing the most to my model and found out the most important feature predicting the winner is players service rating and after that if the player won the first set. Some of the other important features contributing to my model were return rating, break points made and tiebreaks won.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*rxzMuOv3OLeVi-gfweTgRQ.png" /><figcaption>Figure 5 : Permutation importances</figcaption></figure><p>I also plotted a single feature partial dependence plot (fig. 6) to further explore the serve rating feature and it was interesting to find out service rating starts to be important in prediction the winner when its surpasses ~230 points and gradually improves the chances of winning until it gets to~330 points. It worths noting that service rating loses importance in predicting the match results for players who have a service rating of more than ~330 points as they would all have more than 60% chance of winning the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zHfdE_qn6ctegtH7Ec7AIA.png" /><figcaption>Figure 6 : Single feature partial dependence plot for serve rating</figcaption></figure><p>I then moved to figure out how service rating and breakpoints made could contribute to more accurately predict the match results. For that purpose I used a multiple feature partial dependence plot (fig. 7) and just by having a service rating of more than 297 and making more than 3 break points in the game, a player could have a ~90% chance in winning the game. Learning this was a very insightful for me both in the aspect of improving my game and predicting tennis match winners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*cl0ehBOPSB8jSFgmzgYDCA.png" /><figcaption>Figure 7 : Multiple feature partial dependency plot for two of the most important features in my model</figcaption></figure><p>I also used Shapley plots to briefly explore what features are impacting a single match in the model, positively or negatively and how strong is their impact in predicting that particular match. As laid down below in figure 8 if players serve rating is 178 or lower, he only makes 1 break point and he lost the first set, we can predict with almost 100% certainty that he will end up losing the game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IuAy552l4amrXl5uL5PMcw.png" /><figcaption>Figure 8 : Shapley plot</figcaption></figure><h3>Conclusion</h3><p>From all the linear and tree based models use XGboost performed best delivering 96% accuracy in predicting the match results. During the process I learned some of the most important metrics in predicting the winner in a tennis match are rating of the player’s service and return, breakpoints made, tiebreaks won and wether the player was successful in winning the first set.</p><p>I would like to expand this model by figuring out the important parameters of predicting the winner of the first set using the data derived from the first set and history of head to head matches between the players and I’ll be posting the results here and in my portfolio. Until then I’m going to put my money where my mouth is and try to live predict a game using my finding here, and try to improve my game by focusing on landing better services, improve my returns, landing more breakpoints, winning tiebreaks and doing my best in winning the first set.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37f346377663" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/let-data-improve-your-tennis-game-37f346377663">Let Data Improve Your Tennis Game</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Happiness, Life Expectancy, Income Inequality and Your Tax Dollars]]></title>
            <link>https://medium.com/@amindazad/happiness-life-expectancy-income-inequality-and-your-tax-dollars-c1088089c69b?source=rss-cf1382641795------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1088089c69b</guid>
            <category><![CDATA[happiness]]></category>
            <category><![CDATA[progressive]]></category>
            <category><![CDATA[income-inequality]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Amin Azad]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 06:29:18 GMT</pubDate>
            <atom:updated>2020-06-19T23:25:08.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3I-MmdXwWhOjN2Jg_lXwA.png" /></figure><h4>What can we learn from data about the tax income relationship with happiness, life expectancy and income inequality among democratic market driven economies.</h4><p>Since the great depression democrats and republicans have disagreed on tax policy in almost every election and as we approach the 2020 presidential election candidates in both state and federal level have proposed over 300 tax policy proposals on both sides of political spectrum. Tax plans say a lot about candidates’ policy goals, how they view the role of government and how they plan to accomplish their goals. But, what’s the purpose of taxation and why it’s important that everyone pays their fair share ?</p><p>U.S. Department of Treasury describes the main purpose of taxes <em>is to be used for public investment, the production of public goods and to improve social welfare by redistributing income in the entire population</em>. To simplify it, we pay taxes so the government could have enough resources to ensure our safety and well being.</p><p>Two main political parties in the United States have a different interpretation of taxation and its effectiveness to deliver safety and wellbeing to the society.The democrats argue for effectiveness of taxation in enabling the federal government to improve social safety nets and it turn increase life standards all across the board by raising tax rates, and the republicans side with trickle down economics in which small government would improve society’s well being by cutting taxes and regulations, and in turn providing more wealth and economic freedom to the masses.</p><p>In the following few paragraphs we are going to take a closer look at the economic data of democratic market driven economies (OECD) all over the globe and try to evaluate which school of thought has delivered better results for the masses in 2018. We are going to cover 2018 data since 2019 economic datasets for some of OECD countries has not been published yet.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F50.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F50%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/94198eae5b569d415b97e539ef798696/href">https://medium.com/media/94198eae5b569d415b97e539ef798696/href</a></iframe><h4><strong>Taxes Rates and Life Expectancy</strong></h4><p>Life expectancy measures the average length of life for the whole society and it is often used to compare quality of healthcare system among nations. High life expectancy could be a good proof for an effective high quality healthcare system available to the majority of society.</p><p>All OECD countries but the United States use a single payer healthcare system in which healthcare is guaranteed for every citizen and is funded through public funds. Figure 1 demonstrates the positive linear relationship between tax rates and life expectancy among OECD countries and size of each bubble indicates size of each economy adjusted by population. Now, we must keep in mind that correlation doesn’t imply causation and to scientifically proof that higher taxes result in higher life expectancy we need to include more data but it’s safe to say that as tax rates rise , life expectancy tends to increase in democratic market driven countries.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F5.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F5%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/baa10d52b5465854fab42b8bbc74209f/href">https://medium.com/media/baa10d52b5465854fab42b8bbc74209f/href</a></iframe><p>Figure two could show us where each country stands when it comes to life expectancy’s relationship with tax rates. We can see citizens of countries with higher tax rates were able to purchase a few extra years with their tax money.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F2.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F2%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/52fde2b21119a774562188f0887f027f/href">https://medium.com/media/52fde2b21119a774562188f0887f027f/href</a></iframe><h4><strong>Tax Rates and Income Inequality</strong></h4><p>In order to measure the impact of the tax policy on income inequality, it is important to understand how income inequality itself is measured. There are a variety of different ways to measure income inequality, each with its own strengths and weaknesses. Each metric, however, tells essentially the same story about income equality in the United States; We have relatively high levels of income inequality, income inequality has gotten worse over time, and the tax policy can make a significant difference in income inequality.</p><p>The most comprehensive and widely used measure of income inequality is the Gini index. This index (also known as the Gini coefficient, Gini ratio, or Gini score) essentially measures the difference between actual income distribution and a perfectly equitable distribution in which everyone makes the same amount. A perfectly equitable distribution of income scores a 0 on the Gini index, whereas the most unequal distribution, in which a single person makes all the income, scores a 1.</p><p>Taking a closer look at figure 3, we can see the correlation line between Gini coefficient and average tax rates is almost flat meaning based on our data set income inequality and average tax rates are not correlated. It is interesting that we were not able to find a relationship between the two using out dataset as one of the main functions of tax policy is to redistribute income across the whole population. It might be possible though to find the positive or the negative relationship between income inequality and tax rates by expanding our dataset through increasing time period but that remains to be done at another time.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F13.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F13%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b90c7bd2e786dc150694ee0aface407/href">https://medium.com/media/2b90c7bd2e786dc150694ee0aface407/href</a></iframe><h4>Tax Rates and Happiness Index</h4><p>While the definition of individual happiness varies person-to-person, the UN Sustainable Development Solutions Network has managed to put some parameters around the otherwise abstract term. In order to compile their annual <a href="http://worldhappiness.report/">World Happiness Report</a>, the team studies factors like GDP per capita, social support, healthy life expectancy, freedom to make life choices, generosity and perception of corruption in order to rank each country’s overall happiness.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F15.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F15%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7375465ccd1c9227d536e21a43f351f/href">https://medium.com/media/b7375465ccd1c9227d536e21a43f351f/href</a></iframe><p>As we can see in figure 4 there is a positive correlation between happiness score and average tax rates. While it’s important to note the difference between correlation and causation, many of the world’s happiest countries among OECD have higher average income taxes than the United States.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F18.embed%3Fautosize%3Dtrue&amp;display_name=Plotly&amp;url=https%3A%2F%2Fplot.ly%2F%7Eamindazad%2F18%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=plot" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/de014fe1bb0aee4cb0fe620f5e9411bb/href">https://medium.com/media/de014fe1bb0aee4cb0fe620f5e9411bb/href</a></iframe><p>In examining the income tax rates of some of the happiest countries in the world, 14 of the 17 countries that have been deemed happier than the United States have higher income tax rates. It would, however, be unfair to say that taxes are the only factor in a country’s happiness. Even if it’s not immediately apparent, taxes do play a role in each of the six ranking factors (GDP per capita, social support, healthy life expectancy, freedom to make life choices, generosity and perception of corruption).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1088089c69b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>