<?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 T.J. Kyner on Medium]]></title>
        <description><![CDATA[Stories by T.J. Kyner on Medium]]></description>
        <link>https://medium.com/@tjkyner?source=rss-1c58c02d7211------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bp2kAMo_rVScUiiod4jDSw.jpeg</url>
            <title>Stories by T.J. Kyner on Medium</title>
            <link>https://medium.com/@tjkyner?source=rss-1c58c02d7211------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 13:56:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tjkyner/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[Iterative Imputation with Scikit-learn]]></title>
            <link>https://medium.com/data-science/iterative-imputation-with-scikit-learn-8f3eb22b1a38?source=rss-1c58c02d7211------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f3eb22b1a38</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[imputation]]></category>
            <category><![CDATA[scikit-learn]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[T.J. Kyner]]></dc:creator>
            <pubDate>Mon, 09 Aug 2021 17:58:30 GMT</pubDate>
            <atom:updated>2021-08-10T18:16:37.213Z</atom:updated>
            <content:encoded><![CDATA[<h4>Enhancing model results with an advanced imputation strategy</h4><h3>Introduction</h3><p>While having a nice, clean dataset with minimal preprocessing needs is the ideal scenario for many data scientists, real world data is typically anything but ideal. Certain preprocessing steps such as normalization and transformation aid in creating the best model possible, but are technically optional — that is, a model can be created without these steps if one ignores the differences in output quality. One issue that commonly arises that cannot be ignored, however, is <em>missing</em> data.</p><p>The process of filling in missing data with a given statistical method is known as imputation and comes in a variety of flavors. In this article, I’ll discuss some of the most common imputation methods and compare them with a more advanced method, <strong>iterative imputation</strong>, that can lead to enhanced model results.</p><h3>Common Imputation Methods</h3><p>Some of the most common imputation methods include filling in missing data with either the <strong>mean or median </strong>of a given variable based on the data that does exist. Deciding between the two depends largely on the data being worked with. In instances where the data is skewed one way or the other, the median is likely more appropriate. Conversely, data that is normally distributed can use either the mean or the median as both will be relatively the same. Let’s take a look at a couple ways to implement them.</p><h4>Using NumPy and Pandas</h4><p>Imputing values with NumPy and Pandas is a piece of cake. In the example below, both columns A and B have one missing value each. Column A then has its mean taken using the nanmean() function in NumPy which calculates the mean while ignoring any missing values. The same process is applied to column B with the median instead. The fillna() function is then applied to each column to fill in the missing values. The output of this code is shown below with the righthand side containing the imputed values for each respective column.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cedd1ef1773a415d46dde75d33d5a1d/href">https://medium.com/media/5cedd1ef1773a415d46dde75d33d5a1d/href</a></iframe><figure><img alt="The original and imputed dataframes using NumPy and Pandas" src="https://cdn-images-1.medium.com/max/661/1*EJcxTaY4V3bc0HPQZ7JlfA.png" /><figcaption>Image by author. Output of the code directly above.</figcaption></figure><h4>Using SimpleImputer</h4><p>Scitkit-learn’s SimpleImputer (<a href="https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html">view documentation</a>) is another way to impute missing values. While it may seem slightly more convoluted than the example with NumPy and Pandas, there are a few key benefits to using SimpleImputer. First, the missing value can be set to whatever value you’d like and does not have to be equivalent to np.nan as it does using the fillna() function in Pandas. Additionally, the imputation strategy can easily be changed between one of the following four options simply by altering the strategy argument:</p><ul><li>&quot;mean&quot; — replaces missing values with the mean</li><li>&quot;median&quot; — replaces missing values with the median</li><li>&quot;most_frequent&quot; — replaces missing values with the most frequent value</li><li>&quot;constant&quot; — replaces missing values with whatever value is specified in the fill_value argument. This could be useful in a scenario in which you want to replace missing values with a string saying “missing” rather than an actual value.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90b58da4f385fa4be26527a11877dbc7/href">https://medium.com/media/90b58da4f385fa4be26527a11877dbc7/href</a></iframe><figure><img alt="The original and imputed dataframes using SimpleImputer in scikit-learn" src="https://cdn-images-1.medium.com/max/459/1*5pRNfnRM1unQiLtlSNU-Og.png" /><figcaption>Image by author. Output of the code directly above.</figcaption></figure><h3>Iterative Imputation</h3><p>Useful only when working with multivariate data, the IterativeImputer in scikit-learn (<a href="https://scikit-learn.org/stable/modules/generated/sklearn.impute.IterativeImputer.html#sklearn.impute.IterativeImputer">view documentation</a>) utilizes the data available in other features in order to estimate the missing values being imputed. It does so through an…</p><blockquote>…iterated round-robin fashion: at each step, a feature column is designated as output y and the other feature columns are treated as inputs X. A regressor is fit on (X, y) for known y. Then, the regressor is used to predict the missing values of y. This is done for each feature in an iterative fashion, and then is repeated for max_iter imputation rounds. The results of the final imputation round are returned. [<a href="https://scikit-learn.org/stable/modules/impute.html#iterative-imputer">Source</a>]</blockquote><p>If that still seems a bit abstract, hopefully the following example will help clear things up. Due to the IterativeImputer still being experimental, importing enable_iterative_imputer is a requirement for use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/192b3878930ec50c9d38135c4997eb64/href">https://medium.com/media/192b3878930ec50c9d38135c4997eb64/href</a></iframe><figure><img alt="The original and imputed dataframes using IterativeImputer in scikit-learn" src="https://cdn-images-1.medium.com/max/548/1*MUWaapDQPlW4f6zmfaZN4g.png" /><figcaption>Image by author. Output of the code directly above.</figcaption></figure><p>The underlying pattern for this dummy data was intended for column B to be the square of column A. While not perfect, the IterativeImputer did result in a value somewhat close to the “true” value of 16.0 being filled in. Comparing the result to what would have been achieved using a mean imputation strategy (12.7) or a median imputation strategy (9.0) clearly shows the benefit of using an iterative imputation strategy in this case.</p><h3>A Comparison using Real Data</h3><p>I recently had an opportunity to put the IterativeImputer to test with a real world dataset while creating a <a href="https://github.com/tjkyner/australian-rain-prediction">next-day prediction model for rain in Australia</a>. While I won’t be detailing the entire project here, it does serve as a good example of how iterative imputation can be more beneficial than some of the simpler strategies. Using the weatherAUS.csv file from the <a href="https://www.kaggle.com/jsphyg/weather-dataset-rattle-package">source dataset</a>, the continuous features are imputed below using three different strategies:</p><ol><li>Mean imputation</li><li>Median imputation</li><li>Iterative imputation</li></ol><p>I chose to compare the Pressure9am and Pressure3pm features as they are directly related to one another and exhibit a linear relationship which will be useful for evaluation purposes. The code below imputes the missing data with the three different strategies, plots the data along with a regression line, and then displays the <a href="https://en.wikipedia.org/wiki/Root-mean-square_deviation">root mean squared error</a> (RMSE, lower is better).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/013dad939b4f580480131dde456f635d/href">https://medium.com/media/013dad939b4f580480131dde456f635d/href</a></iframe><figure><img alt="Plots comparing the mean, median, and iterative imputation strategies along with the RMSE values" src="https://cdn-images-1.medium.com/max/1024/1*24xqLv0M88OLrAN2Pl7iUA.png" /><figcaption>Image by author. Output of the code directly above.</figcaption></figure><p>Without even paying attention to the RMSE values, the iterative imputation strategy should stand out as having better fit values just by looking at it. Since the mean and median strategies fill in all missing values with the same value, a cross-like shape is formed near the center of the data that does not necessarily fit the overall trend. The iterative imputation strategy, however, is able to utilize the information contained in other features to approximate the value instead, leading to a much cleaner plot that more accurately fits the trend.</p><p>You may be thinking that an improvement in the RMSE from 1.874 to 1.871 is not that big of a deal — and you’d be right. While not anything spectacular on its own, there’s a couple things to keep in mind:</p><ol><li>The amount of missing data in the Pressure9am and Pressure3pm features was only about 10%. As a result, the RMSE values can only improve so much compared to the mean and median strategies.</li><li>This comparison is only looking at two features while the full dataset contains many more. Small improvements across each of these features can lead to a large improvement overall when using all of the data in the modeling process.</li></ol><h3>Conclusion</h3><p>Simple imputation strategies such as using the mean or median can be effective when working with univariate data. When working with multivariate data, more advanced imputation methods such as iterative imputation can lead to even better results. Scikit-learn’s IterativeImputer provides a quick and easy way to implement such a strategy.</p><p><strong>Github</strong>: <a href="https://github.com/tjkyner">https://github.com/tjkyner</a><br><strong>Medium</strong>: <a href="https://tjkyner.medium.com/">https://tjkyner.medium.com/</a><br><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/tjkyner">https://www.linkedin.com/in/tjkyner/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f3eb22b1a38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/iterative-imputation-with-scikit-learn-8f3eb22b1a38">Iterative Imputation with Scikit-learn</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[Evaluating Classification Models]]></title>
            <link>https://medium.com/geekculture/evaluating-classification-models-3a28a569962c?source=rss-1c58c02d7211------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a28a569962c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[classification-models]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[confusion-matrix]]></category>
            <dc:creator><![CDATA[T.J. Kyner]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 02:17:07 GMT</pubDate>
            <atom:updated>2021-09-20T00:57:37.252Z</atom:updated>
            <content:encoded><![CDATA[<h4>An overview of commonly used tools and metrics</h4><h3>Introduction</h3><p>Classification models represent some of the most useful and practical algorithms in the machine learning world. From predicting whether it will rain to determining fraudulent activity on credit cards, these types of models use the available data given to them to classify their predicted outputs into two or more groups. A variety of strategies to tackle classification problems have arisen over the years including logistic regression, decision trees, k-nearest neighbors, and many more.</p><figure><img alt="Example of a complex decision tree with many branches and nodes." src="https://cdn-images-1.medium.com/max/432/1*4W89StobCKMHS5kGh3C4KQ.png" /><figcaption>Example of a complex decision tree. Image by author.</figcaption></figure><p>Given the different strategies available, a natural question arises: <strong>How can classification models be evaluated and compared to one another? </strong>While the actual process of building classification models will be saved for another time, this article will walk you through some of the most common evaluation tools and metrics available.</p><h3>The Confusion Matrix</h3><p>Before diving in to the specific metrics commonly used to answer the above question, we must first cover the basics. We’ll only be looking at binary classification models in order to keep things simple, but know that the concepts that follow are easily extendable to multi-dimensional data as well. A confusion matrix, despite its name, is fairly straightforward. It shows us how the predictions of a model stack up against the true and correct values, also known as the ground-truth. Let’s see an example:</p><figure><img alt="Example of a confusion matrix showing 114 true negatives, 23 false negatives, 66 true positives, and 20 false positives." src="https://cdn-images-1.medium.com/max/900/1*56Yy_Z4SFC5eeSTd_us0nw.png" /><figcaption>Example of a confusion matrix. Image by author.</figcaption></figure><p>There are four key takeaways from this, one for each quadrant:</p><ol><li><strong>True Negatives (TN)</strong> are the number of predictions where the predicted label was 0 and the ground-truth label was also 0. This can be found in the top left quadrant. Note: negative in this context does not necessarily mean a negative value but rather one part of a binary representing true/false, on/off, alive/dead, etc.</li><li><strong>True Positives (TP)</strong> are similar to true negatives but for the opposing label (in this case, 1). This can be found in the bottom right quadrant.</li><li><strong>False Negatives (FN)</strong> are scenarios in which the model predicted a negative value when the ground-truth was actually positive. This can be found in the bottom left quadrant.</li><li><strong>False Positives (FP)</strong> are scenarios in which the model predicted a positive value when the ground-truth was actually negative. This can be found in the top right quadrant.</li></ol><p>These four pieces of information can be combined in various ways to describe the overall effectiveness of a model. Let’s now take a look at some of those specific metrics.</p><h3>Metrics</h3><h4>Accuracy</h4><p>The most intuitive of the metrics, accuracy is essentially a measure of how many predictions of a model were correct — that is, aligned with the ground-truth.</p><figure><img alt="The formula for accuracy. TP plus FP over TP plus FN plus TN plus FP." src="https://cdn-images-1.medium.com/max/1024/1*N5tJ3YjejkcWCG57KHH9MQ.png" /><figcaption>Formula for Accuracy. Image by author.</figcaption></figure><p>While it may seem that nothing more is needed beyond this metric, relying solely on accuracy to evaluate a classification model is a mistake. Consider the following commonly referenced scenario used to highlight this issue: 100 patients are being tested for a disease that occurs in only 1% of people. A model which predicts that no one has the disease at all would technically have a 99% accuracy rate yet be completely useless for actually finding patients that are infected!</p><p>Using the values found in the confusion matrix example, the accuracy would be approximately 80.72%.</p><h4>Precision</h4><p>The positive predictions of a model contain both true positives and false positives. Precision takes a look at all of the predicted positive values and determines what percentage were true positives.</p><figure><img alt="The formula for precision. TP over TP plus FP." src="https://cdn-images-1.medium.com/max/1024/1*slDE9MTnSuKYnUwtfepM9g.png" /><figcaption>Formula for Precision. Image by author.</figcaption></figure><p>Using the values found in the confusion matrix example, the precision would be approximately 76.74%.</p><h4>Recall</h4><p>Recall scores the number of true positives predicted by the model as a percentage of the total number of ground-truth positives.</p><figure><img alt="The formula for recall. TP over TP plus FN." src="https://cdn-images-1.medium.com/max/1024/1*VkW4Szh9CVXakAUgxcpSKQ.png" /><figcaption>Formula for Recall. Image by author.</figcaption></figure><p>Think about this metric in the context of the disease scenario mentioned in the Accuracy section. While the accuracy would be 99%, the recall would be 0% since there would be zero true positives and one false negative (the patient that actually had the disease but the model automatically classified as not having the disease).</p><p>Using the values found in the confusion matrix example, the recall would be approximately 74.16%.</p><h4>F1 Score</h4><p>Precision and recall exhibit an inverse relationship and their relative importance depends entirely on the context of the data being worked with. In general, having high scores in both metrics is preferable. The F1 score represents the <a href="https://en.wikipedia.org/wiki/Harmonic_mean">harmonic mean</a> of precision and recall and acts as a measure of the balance between the two.</p><figure><img alt="The formula for F1 score. 2 time recall times precision over precision plus recall." src="https://cdn-images-1.medium.com/max/1024/1*F1FRDBfvXFwAQzr-7UWt5A.png" /><figcaption>Formula for F1 Score. Image by author.</figcaption></figure><p>As a result of using a harmonic mean instead of an arithmetic mean, the F1 score can only have a high value when <em>both </em>precision and recall have high values. A low value in either metric will significantly skew the F1 score lower in response.</p><p>Using the values found in the confusion matrix example, the F1 score would be approximately 75.43%.</p><h3>ROC Curves</h3><p>For those hoping for a more visual evaluation method of classification models, you’re in luck. The Receiver Operating Characteristic (ROC) Curve plots the false positive rate against the true positive rate and provides a quickly interpretable visualization of model effectiveness.</p><figure><img alt="An example of an ROC curve using a logistic regression model. The area under the curve equals 0.88." src="https://cdn-images-1.medium.com/max/900/1*mdl7EofcO1JokW-Cs6xyNQ.png" /><figcaption>Example of an ROC Curve. Image by author.</figcaption></figure><p>The diagonal dotted line represents a model that is randomly guessing. Useful models which have some degree of predictive power will have curves that extend towards the upper left. In this example, a logistic regression model’s performance is shown by the blue line. The ROC curves of multiple model iterations and types can be overlaid on the same graph for a quick comparison. Individual curves can still be quantitatively evaluated and compared by measuring the areas under the curves (AUC) via <a href="https://en.wikipedia.org/wiki/Integral">integration</a>. In the example above, this value is denoted by “AUC = 0.88&quot;. A model which perfectly classifies all values would have an AUC of 1.00.</p><h3>Conclusion</h3><p>Understanding these tools and metrics and what differentiates them from one another is key to properly evaluating the performance of classification models. Different problems will require tuning models to optimize different metrics according to what makes the most sense for the domain. While additional evaluation methods exist, the topics covered in this article provide a solid foundation.</p><p>If you liked this article, make sure to let me know by leaving a 👏 or a comment with any feedback!</p><p><strong>Github</strong>: <a href="https://github.com/tjkyner">https://github.com/tjkyner</a><br><strong>Medium</strong>: <a href="https://tjkyner.medium.com/">https://tjkyner.medium.com/</a><br><strong>LinkedIn</strong>: <a href="https://www.linkedin.com/in/tjkyner">https://www.linkedin.com/in/tjkyner/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a28a569962c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/evaluating-classification-models-3a28a569962c">Evaluating Classification Models</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Normal Distribution vs. Student’s T-Distribution]]></title>
            <link>https://tjkyner.medium.com/the-normal-distribution-vs-students-t-distribution-322aa12ffd15?source=rss-1c58c02d7211------2</link>
            <guid isPermaLink="false">https://medium.com/p/322aa12ffd15</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[t-distribution]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[normal-distribution]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[T.J. Kyner]]></dc:creator>
            <pubDate>Fri, 28 May 2021 01:23:52 GMT</pubDate>
            <atom:updated>2021-05-28T01:38:09.721Z</atom:updated>
            <content:encoded><![CDATA[<h4>An intuitive visualization of why we use t-distributions</h4><h3>Introduction</h3><p>In this article I attempt to provide an intuitive visualization of why Student’s t-distribution is often used over the normal distribution. Many introductory statistics and data science courses provide a rationale for the use of t-distributions along the lines of it being useful in situations where either the sample size is small and/or the population’s standard deviation is unknown. While correct, the rationale remains abstracted through such an explanation and learners may achieve a more powerful understanding through a clear and simple visualization.</p><h3>The Normal Distribution</h3><p>The normal distribution, also sometimes referred to as a bell curve, is one of the most frequently used distributions and often the starting point for learning about distributions in general due to its relative simplicity. Given a mean (<em>μ</em>) and standard deviation (<em>σ</em>), a normal distribution can be modeled with the following probability density function:</p><figure><img alt="The generic form probability density function for a normal distribution" src="https://cdn-images-1.medium.com/max/863/1*Zd2BQgB94XEev8-3mMLMlw.png" /><figcaption>The probability density function for a normal distribution</figcaption></figure><p>A variety of different Python libraries makes visualizing a normal distribution fairly simple. The code below outputs a graph of a special type of normal distribution called the <em>standard </em>normal distribution — i.e., where the mean is explicitly equal to zero and the standard deviation is explicitly equal to one.</p><h4>Code:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b59cc30620424dfc50e80539b7d88b7/href">https://medium.com/media/7b59cc30620424dfc50e80539b7d88b7/href</a></iframe><h4>Explanation:</h4><p>For those not familiar with Python or programming in general, here’s a quick explanation of what the above code is doing:</p><ul><li>Imports the various libraries used for creating the graph</li><li>Sets x equal to 500 evenly spaced values between -4 and +4</li><li>Sets y equal to the output of the normal distribution probability density function at the values of x</li><li>Specifies the labels and title for the graph and then plots the data</li><li>Includes some optional styling methods to make the output look a bit nicer (sns.despine() removes the top and right borders of the graph)</li></ul><h4><strong>Output:</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8bbF0FcQ7_nAW2MmLfkpoA.png" /></figure><h3>Student’s T-Distribution</h3><p>The t-distribution is similar to the normal distribution in many ways but does not assume knowledge of the population mean and standard deviation the way the normal distribution does. The probability density function of the t-distribution is as follows, where Γ represents the <a href="https://en.wikipedia.org/wiki/Gamma_function">gamma function</a> and <em>ν</em> represents the <a href="https://en.wikipedia.org/wiki/Degrees_of_freedom_(statistics)">degrees of freedom</a>:</p><figure><img alt="The probability density function for Student’s t-distribution" src="https://cdn-images-1.medium.com/max/1024/1*Ig962bKPnJBc3JXVXtfang.png" /><figcaption>The probability density function for Student’s t-distribution</figcaption></figure><p>Importantly, the degrees of freedom, calculated as one less than the sample size in most situations, has a large impact on the shape of the distribution at lower values. This will be explored a bit further in the comparison section, but for now let’s visualize a t-distribution with a single degree of freedom.</p><h4>Code:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e809274bee76f3ac905e0f7f30e6db5/href">https://medium.com/media/5e809274bee76f3ac905e0f7f30e6db5/href</a></iframe><h4>Explanation:</h4><ul><li>The above code is largely the same as in the normal distribution section with slight changes on lines 9 and 11</li><li>Line 9 sets the specified degrees of freedom to the df variable</li><li>Line 11 sets y equal to the output of the t-distribution probability density function at the values of x given the df parameter</li></ul><h4>Output:</h4><figure><img alt="A graph of Student’s t-distribution with a single degree of freedom" src="https://cdn-images-1.medium.com/max/1024/1*PwKDnftUxFJS8Nmsn6nFaQ.png" /></figure><h3>A Visual Comparison</h3><p>Now that we’ve seen both the standard normal distribution and a t-distribution with a single degree of freedom, let’s plot them together to see how they compare.</p><h4>Code:</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b27665ae914a60711d67878b2de9eda/href">https://medium.com/media/2b27665ae914a60711d67878b2de9eda/href</a></iframe><h4>Output:</h4><figure><img alt="A graph comparing the standard normal distribution to a t-distribution with one degree of freedom" src="https://cdn-images-1.medium.com/max/1024/1*H9mEMuDivtR5iQ7PXYOQbQ.png" /></figure><h4>Key Differences:</h4><p>With only a single degree of freedom, the t-distribution is much flatter and has fatter tails than the standard normal distribution. The power of the t-distribution comes from its ability to adjust for smaller sample sizes (and therefore less degrees of freedom) by effectively having a more conservative estimate of probability density.</p><p>Put another way, <strong>the t-distribution adjusts for a natural decrease in confidence at lower sample sizes that the normal distribution does not account for.</strong></p><p>At higher degrees of freedom, the t-distribution approximates the normal distribution, making it useful at both small and large sample sizes. The animation below shows a comparison between the t-distribution and the normal distribution at degrees of freedom ranging from 1 to 50.</p><figure><img alt="An animated gif showing a t-distribution vs the normal distribution for degrees of freedom ranging from 1 to 50" src="https://cdn-images-1.medium.com/max/979/1*HY7SXpQIr2s3g0fHsXi9hQ.gif" /></figure><h3>Conclusion</h3><p>And there you have it. Not only does Student’s t-distribution not require information regarding the population mean and standard deviation (which are rarely known in real world experiments), but it also has increased flexibility at various sample sizes. These properties make it much more attractive to use over the normal distribution in most instances.</p><h4>Feedback</h4><p>Any questions, comments, or other feedback? I’d love to hear from you! Feel free to leave a response or shoot me an email at <a href="/service/mailto:tjkyner@gmail.com">tjkyner@gmail.com</a>. If you liked this article and want to see more, make sure to leave a 👏.</p><h4>License</h4><p>The code and images contained within this article were all produced by myself and are released under the <a href="https://choosealicense.com/licenses/gpl-3.0/">GNU General Public License v3.0</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=322aa12ffd15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data visualizations: Choosing colors with purpose]]></title>
            <link>https://uxdesign.cc/data-visualizations-choosing-colors-with-purpose-4a672ac0215a?source=rss-1c58c02d7211------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a672ac0215a</guid>
            <category><![CDATA[visual-design]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[colors]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[T.J. Kyner]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 21:43:53 GMT</pubDate>
            <atom:updated>2021-05-01T11:13:53.828Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Streams of smoke in various different colors." src="https://cdn-images-1.medium.com/max/1024/0*U3ehb0b89knD3GLG" /><figcaption>Photo by <a href="https://unsplash.com/@pawel_czerwinski?utm_source=medium&amp;utm_medium=referral">Paweł Czerwiński</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Visualizations can provide a much more impactful and intuitive sense of data than viewing it in its raw form. There are a plethora of visualization tools and chart types that help convey data in different ways, many of which are particularly useful for specific types of data. While a lot of thought may go into choosing a visualization type, it’s also important to take it a step further and consider the colors used as well.</p><h3>The Impact of Color</h3><h4>Why use it at all?</h4><p>Beyond making visualizations aesthetically pleasing, color can also serve other purposes. One such purpose is adding dimensionality in a world constrained by three-dimensional space. While three-dimensional projections of higher dimensional objects such as the <a href="https://en.wikipedia.org/wiki/Tesseract">tesseract</a> exist, the concept is very difficult for the human brain to wrap itself around. As a result, we’re forced to get a bit creative. Color (along with size, shapes, and more) allows for conveying an additional dimension of data in a non-spatial manner.</p><p>A color map, sometimes also referred to as a palette, is an array of different color values used within a particular visualization or group of visualizations as a broader theme. Limited only by the number of colors a monitor can display (~16.8 million based on the RGB color model), there is no shortage of different possible color maps. However, not all color maps should be considered viable candidates for data visualizations. As an example, let’s take a look at the below heat map (the <em>x</em> and <em>y</em> axes are irrelevant):</p><figure><img alt="A heat map chart using a color map with a wide range of colors that is difficult to interpret." src="https://cdn-images-1.medium.com/max/436/1*r1xrVx4ifdN18PGsHBgNDQ.png" /><figcaption>Photo by Michael Waskom from the Seaborn <a href="https://seaborn.pydata.org/tutorial/color_palettes.html">“Choosing color palettes”</a> Tutorial</figcaption></figure><p>Is it immediately obvious what value each color represents relative to the others? Using the exact same data with a different color map yields the following:</p><figure><img alt="A heat map chart using a color map that makes it clear what the relative values are." src="https://cdn-images-1.medium.com/max/436/1*FQ5UrThFqlzLOsxlu3ETuA.png" /><figcaption>Photo by Michael Waskom from the Seaborn <a href="https://seaborn.pydata.org/tutorial/color_palettes.html">“Choosing color palettes”</a> Tutorial</figcaption></figure><p>Even without having a legend to reference, which had been purposefully withheld from both pictures for the sake of this example, the second image provides a much clearer and intuitive sense of the relative differences in each color value. For those curious, you can view a side-by-side comparison of both images along with their legends in Seaborn’s “Choosing color palettes” tutorial by clicking <a href="https://seaborn.pydata.org/tutorial/color_palettes.html#vary-luminance-to-represent-numbers">here</a>.</p><h4>Color Maps for the Color Blind</h4><p>The incorporation of intuitive color maps in data visualizations is an extremely useful tool, but has one major drawback: the information conveyed by the colors is lost to those who cannot distinguish between them. <a href="https://www.colourblindawareness.org/colour-blindness/">According to the Colour Blind Awareness Organisation</a> (UK-based), approximately 8% of men and 0.5% of women worldwide have some form of color vision deficiency (CVD). Fortunately, certain scientifically derived color maps have been created which are able to maintain distinguishability across various different types of color blindness. Several such color maps are shown below with their corresponding CVD-adjusted perceptions.</p><figure><img alt="A list of color maps that are friendly to people with color blindness and how they look to people with varying color vision deficiencies." src="https://cdn-images-1.medium.com/max/1024/1*l1ygSIhsU36ljbG527lQNQ.png" /><figcaption>Photo from “<a href="https://doi.org/10.1038/s41467-020-19160-7">The misuse of colour in science communication</a>” by Fabio Crameri, Grace E. Shephard, and Philip J. Heron</figcaption></figure><p>In addition to non-CVD vision, each of these color maps provides a logical and continuous scale for different types of color vision deficiencies, including complete color blindness. In contrast, visualizations using color maps that do not keep this information in mind are prone to causing confusion for CVD readers.</p><figure><img alt="A rainbow color map and how it looks to people with various color vision deficiencies." src="https://cdn-images-1.medium.com/max/1024/1*MGfcXEhWcMHSLNLKcEE0Gw.png" /></figure><p>As can be seen in the rightmost color scale perception above (complete color blindness), use of a rainbow color map creates duplicate values at the opposite ends of the spectrum. Color maps that make use of nearly all colors in the visible light spectrum are frequently used but should largely be avoided for this exact reason.</p><h3>Further Examples</h3><p>Given the vast number of both colors and visualization types, an exhaustive list of recommendations for choosing colors with purpose is impractical. The following examples are intended to cover some of the most common errors made when using colors in visualizations.</p><h4>Unnecessary use of colors</h4><p>In some instances, the use of colors can detract from the overall value of a data visualization by conveying information where there is none. While the chart below does make use of a scientifically derived and CVD-friendly color map (viridis), its use is confusing and redundant given the existence of the <em>x</em> axis labels. This chart would be much easier to consume by changing the bars to a single color, dropping the legend, and changing the <em>x</em> axis title to “Brand” instead of “mpg” which is inaccurate.</p><figure><img alt="A bar chart showing the average mpg for different auto manufacturers. The bars are colored according to the brand name of the manufacturer in alphabetical order." src="https://cdn-images-1.medium.com/max/1024/1*LKZu0RkBnUKbJsMRXdo8SQ.png" /><figcaption>Photo by AbdulMajedRaja from programmingwithr.com (<a href="https://www.programmingwithr.com/one-line-code-using-viridis-for-how-to-change-the-color-scale-in-ggplot-plots/">link</a>)</figcaption></figure><p>In defense of the original creator, the primary goal of the article this chart was sourced from revolved around manipulating color maps to fit data in different ways rather than necessarily creating a completely accurate chart. Nevertheless, this represents a prime example of adding unnecessary dimensionality to a data visualization via the use of colors.</p><h4>Non-intuitive colors</h4><p>Context matters. Using colors that have strong associations with particular values in a non-intuitive manner can also make visualizations confusing and harder to interpret. For anyone familiar with American politics, the following map of the results of the 2020 presidential election should look <em>very </em>wrong:</p><figure><img alt="A map of the United States showing the outcome of the 2020 presidential election. States won by the Republican candidate shown in blue while states won by the Democratic candidate are shown in red." src="https://cdn-images-1.medium.com/max/703/1*GYOthJjF1WPcssdEAgalDw.png" /><figcaption>Photo created by me using <a href="https://www.270towin.com/">270towin.com</a></figcaption></figure><p>That gut reaction is in response to the associations of the Democratic party with the color blue and the Republican party with the color red. However, this map is <em>technically</em> 100% accurate given the legend. While this specific example is particularly extreme and unlikely to unintentionally occur, the general issue is something to be considered when creating visualizations.</p><h4>Red and green only</h4><p>Many visualizations that deal with displaying information in response to a “yes” / “no” or “support” / “oppose” question use a red and green color map like the chart below. In Western culture, these colors make intuitive sense given the association of “yes” / “support” / “up” with green and “no” / “oppose”/ “down” with red (side note: this dynamic is reversed in many Eastern cultures). With red-green color blindness being the <a href="https://www.nei.nih.gov/learn-about-eye-health/eye-conditions-and-diseases/color-blindness/types-color-blindness">most common form </a>of color vision deficiency, however, the use of this color map strongly inhibits a sizable portion of the global population from being able to effectively interpret the visualization. A simple exchange of the color map to one that avoids CVD related issues would increase accessibility at no expense to the quality of the visualization.</p><figure><img alt="A chart showing the percentage of Americans that support rejoining the Paris Climate Agreement split into four categories: All US adults, Democrats, Republicans, and Independents. Support is shown in green and opposition is shown in red." src="https://cdn-images-1.medium.com/max/1024/1*NLfhd2BlVUxXsu8A1XejRQ.jpeg" /><figcaption>Photo by Niall McCarthy from Statista (<a href="https://www.statista.com/chart/23474/us-public-view-on-rejoining-paris-climate-agreement/">link</a>) — original data from YouGov</figcaption></figure><h3>Resources</h3><p>Fortunately for data visualization creators, the open-source community has created a number of tools and resources for making the task much simpler. Several of these tools and resources are listed below:</p><ul><li><a href="https://matplotlib.org/"><strong>Matplotlib</strong></a>: one of the most popular visualization libraries for Python, many different scientifically derived color maps come included</li><li><a href="https://seaborn.pydata.org/"><strong>Seaborn</strong></a>: built on top of Matplotlib, this library includes some additional color maps and makes other styling methods a breeze</li><li><a href="https://colorbrewer2.org/"><strong>Colorbrewer</strong></a>: specifically focused on cartographic visualizations, this site allows for selecting different color maps with filtering options for only those that are CVD-safe and/or printer-friendly</li><li><a href="https://www.fabiocrameri.ch/colourmaps/"><strong>Fabio Crameri</strong></a>: a collection of different color maps from one of the authors of the paper that inspired this article (see the Acknowledgements section below)</li><li><a href="http://vrl.cs.brown.edu/color"><strong>Colorgorical</strong></a>: a useful tool for creating color maps with unique parameters such as perceptual distance, name difference, pair preference, name uniqueness, and more</li><li><a href="http://www.ccctool.com/"><strong>CCC-Tool</strong></a>: a tool for creating and exporting color maps with advanced functionalities such as specifying interpolation methods, color difference metrics, and optimizations</li></ul><p><strong>Acknowledgements: </strong>This article was largely inspired by “<a href="https://doi.org/10.1038/s41467-020-19160-7">The misuse of colour in science communication</a>” by Fabio Crameri, Grace E. Shephard, and Philip J. Heron which was graciously released under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a> in the <em>Nature Communications</em> journal. For those seeking a deeper, more scientific approach to this topic, I highly recommend reading their paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/94/0*RgxBX_Oyalodkdt0" /><figcaption>The UX Collective donates US$1 for each article published on our platform. This story contributed to <a href="https://www.wcd.school/">World-Class Designer School</a>: a college-level, tuition-free design school focused on preparing young and talented African designers for the local and international digital product market. Build the design community you believe in.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a672ac0215a" width="1" height="1" alt=""><hr><p><a href="https://uxdesign.cc/data-visualizations-choosing-colors-with-purpose-4a672ac0215a">Data visualizations: Choosing colors with purpose</a> was originally published in <a href="https://uxdesign.cc/">UX Collective</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>