<?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 Mike Anderson on Medium]]></title>
        <description><![CDATA[Stories by Mike Anderson on Medium]]></description>
        <link>https://medium.com/@mikeanderson0289?source=rss-4696f3a065b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-077SGjaM5gcDaPL6yT8-A.jpeg</url>
            <title>Stories by Mike Anderson on Medium</title>
            <link>https://medium.com/@mikeanderson0289?source=rss-4696f3a065b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 13 Apr 2026 11:22:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikeanderson0289/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[The Preprocessing Survival Guide for New Data Scientists / ML Engineers]]></title>
            <link>https://medium.com/@mikeanderson0289/the-preprocessing-survival-guide-for-new-data-scientists-f0035fc5b319?source=rss-4696f3a065b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0035fc5b319</guid>
            <category><![CDATA[data-science-careers]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mike Anderson]]></dc:creator>
            <pubDate>Sun, 22 Jun 2025 22:23:21 GMT</pubDate>
            <atom:updated>2025-06-22T22:46:44.706Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmSTVBSLwIcMj69lmAxUDg.png" /></figure><p>Over the years, I’ve seen many new grads and junior data scientists and machine learning engineers make some common mistakes that are easily avoided…if you know to look for them.</p><p>Most people are trained on toy datasets that are perfectly arranged, cleaned of all nulls, have identical string formatting, and play super nice for teaching purposes. The reality is that most data is messy, dirty, pulled from anywhere and everywhere, requires a lot of cleanup, and would make the most advanced model available predict hot garbage.</p><p>That being said, a lot of new data scientists (through no fault of their own) just aren’t prepped for the brutal reality of production-grade data. Sometimes the tools they’ve learned <em>do</em> apply — just not in the way they’ve seen them taught.</p><p>For this first lesson, I’m focusing on <strong>preprocessing</strong>. It all ties back to one central theme:</p><blockquote><strong>KNOW. YOUR. DATA.</strong></blockquote><h3>1. Filling Nulls Without Context</h3><p>You always hear about null imputation, but very few people stop to think about <em>what exactly that means. </em>I mean, the concept is fairly straightforward, right? You fill nulls with actual values to get rid of the nulls. Pretty simple.</p><p>However, I see a <em>ton</em> of junior (and some senior) data scientists and machine learning engineers assume that all nulls are made equal. They’re not. You have to look into <em>what you’re actually doing to the data </em>and <em>what the nulls mean</em>.</p><p>For instance, if you pull in data for sales by product by month and you have some nulls in there, your first instinct may be “oh, I should impute this with the mean”. NO. Your next thought may be “I should impute it with the mean per month for that product”. ALSO NO.</p><p>You should instead think about what the nulls mean in the context. In this instance, it means that that specific product for that specific month had NO SALES. Which means, those nulls are <em>actually </em>indicating a 0, not a null. The nulls arise because the database you’re querying or dataset you’re using doesn’t have <em>any</em> data for that specific product/month combination and will return a null, but in reality that null indicates a true, actual 0, which is far more important and <em>accurate</em> than an imputed mean. Therefore, you should impute nulls with 0 in this case, not with the mean or median.</p><p>Along the same lines, people often assume that you need to impute with the mean. This isn’t always the case. If your data distribution is super-skewed or has really long tails, the mean isn’t a good indicator of the actual average and it’s far better to impute with the median.</p><p>My favorite example is house prices. Say you want the average house price in a certain area and in that area are 10 houses that are each $500,000. Your mean is $500,000 and your median is $500,000. Now add one, singular outlier for a guy that builds a $10 million house in the same area. Because of that one house, your mean now jumps to a whomping $1,363,636, almost 3 times the average. Meanwhile, your median doesn’t flinch — it’s still $500,000.</p><p>This is a simple example, but blow that up to having 750 houses and around 50 outliers, and you’ll see that the median is definitely the way to go.</p><p>While I’m on the topic, I’ll also go into imputation by category. You don’t want to fill in the mean/median/mode/etc. for the <em>entire dataset</em>. If you have specific categories to split on, fill in nulls using the averages for those categories. The goal of null imputation is to intuitively guess which values should be in the fields that are missing, and filling in categorically will get you closer to what should really be there. A more robust method of null imputation is K-Means imputation, but I’ll save that for another post.</p><p>Bottom line: There’s no one-size-fits-all for nulls. Context is king.</p><h3>2. Dropping Duplicates</h3><p>Everyone probably knows this little block of code:</p><pre>df.drop_duplicates()</pre><p>However, again, we need to think about what it’s <em>actually </em>doing. It’s looking at every line of the dataframe and comparing each entry to see if any two lines are the same. Pretty simple.</p><p>Now, what if you have 2 lines for the same product, same category, same price, etc., but you have <em>one singular space </em>at the end of the product description for one of them? Just like that, drop_duplicates acts like it doesn’t even see them — because technically, it doesn’t.</p><p>Instead, intuitively think about how you’re dropping duplicates. Try dropping duplicates by id or by several columns like so:</p><pre>df.drop_duplicates(subset=[&#39;product_id&#39;])<br>df.drop_duplicates(subset=[&#39;product_id&#39;, &#39;product_category&#39;])</pre><p>This will save you a lot of headache, especially for text-heavy dataframes like product descriptions or social media posts.</p><h3>3. Forgetting to Scale or Normalize</h3><p>Please, please, please remember to scale/normalize your data. Some models don’t care if your data’s all over the place (looking at you, tree-based models). But others? They’ll have a full-blown meltdown if your features aren’t scaled properly.</p><p>For tree-based models (Random Forest, XGBoost, LightGBM, etc.), they determine predictions based on node splits and thresholds, which work fine with unscaled data. Under the hood, a house price prediction tree-based model with features like square feet and number of stories will go:</p><p>“Is the square feet above or below 2500? Great, now let’s check if the number of stories is more than 2.”</p><p>However, with models like KNN, Neural Networks, Logistic Regression, SVM, etc., it’s actually computing <em>distances between points</em>, and that can get really, really messy and inaccurate if you have some features WAY bigger or smaller than others. To correct for this, you use scaling with functions like StandardScaler or MinMaxScaler. Essentially, it puts all of your data into a uniform, confined space.</p><p>Now, when do you use MinMaxScaler vs. StandardScaler? Here’s a quick breakdown:</p><p><strong>MinMaxScaler</strong></p><ul><li>The data is already bounded between certain numbers — think percentages which are bounded between 0 and 100 or 0 and 1.</li><li>You’re using distance based models (KNN, K-Means, Neural Networks, etc.)</li><li>You want to preserve the shape of the data distribution</li></ul><p><strong>StandardScaler</strong></p><ul><li>Data is normally distributed (or at least centered around a mean)</li><li>You’re using models that assume normality like Logistic Regression, Linear Regression, SVM, etc.</li><li>You want outliers to remain visible and not shoved into a predetermined range</li></ul><h3>4. One-Hot Encoding Explosion</h3><p>If you had some data for demographics all over the world and had a categorical column for “Country”, how many potential columns would you have after one-hot encoding that singular column?</p><p>That’s right: <strong>195</strong></p><p>Now, multiply that by every categorical column you have in your data and you’ll soon end up with hundreds, if not thousands, of columns of nothing but 1s and 0s. Not only does it make your model run slower, but model explainability would be an <em>absolute nightmare</em>.</p><p>Instead, try feature engineering. Get rid of the “Country” column and group things by statistical similarity using something like K-Means clustering or try bucketing the countries into “Europe”, “Asia”, etc. or into population buckets. Do whatever you can to preserve accuracy while keeping the number of columns under control.</p><p>Sometimes, the one-hot encoding explosion is unavoidable, but for those instances you would use a feature decomposition algorithm like PCA after the fact, which I’ll go into in another post (and no, PCA isn’t just for reducing dimensions — it can also help your sanity).</p><h3>5. Removing Outliers Before Analysis and Imputation</h3><p>Say you have a set of 10 balls, 6 are red, 2 are yellow, and 2 are green with yellow balls being super heavy. Now, say you remove outliers based on weight and all of a sudden your yellow balls are out of the picture. What would your data look like?</p><p>First, your model would assume that the only categories that balls could <em>ever</em> be are red and green. Next, it would assume that the average weight is somewhere between the weight of the red balls and green balls. Your model would be based entirely upon these assumptions and wouldn’t reflect the <em>reality</em> in the slightest.</p><p>When you’re removing outliers, you need to carefully examine them to determine if they’re truly outliers or indicators of a deeper meaning. In this instance, the higher weights indicate a specific kind of ball to the point that if a model sees that weight, it’ll automatically go “AHA! YELLOW!” You don’t want to remove that, as it’s incredibly useful information.</p><p>This goes back to my main mantra: <strong>Know your data</strong>.</p><h3>Conclusion</h3><p>Preprocessing might not be the most awesome or hi-tech part of data science, but it’s where most of the modeling magic (or train wrecks) begin. If you skip over it or do it blindly, you’re basically building a castle on quicksand.</p><p>So, next time you’re wrangling data, slow down. Ask yourself what the data <em>means</em>, not just what shape it’s in. There’s a reason seasoned data scientists spend 90% of their time on preprocessing and data collection and maybe 5% on actual model development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0035fc5b319" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>