<?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 Nana on Medium]]></title>
        <description><![CDATA[Stories by Nana on Medium]]></description>
        <link>https://medium.com/@piananas?source=rss-50556bbdbccd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mm9FpzEu2KFMOmiqcLZTKQ.jpeg</url>
            <title>Stories by Nana on Medium</title>
            <link>https://medium.com/@piananas?source=rss-50556bbdbccd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:20:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piananas/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[Feature Engineering Step-by-Step]]></title>
            <link>https://medium.com/@piananas/feature-engineering-step-by-step-3d389878bee2?source=rss-50556bbdbccd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d389878bee2</guid>
            <category><![CDATA[feature-selection]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[prédiction]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Nana]]></dc:creator>
            <pubDate>Sun, 16 Feb 2025 11:35:00 GMT</pubDate>
            <atom:updated>2025-02-19T11:13:50.079Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*udUokjPWYvDy2mhwSnAD1Q.jpeg" /><figcaption>credit: freepik Phonlamaistudio</figcaption></figure><p><strong>Feature Engineering</strong> in Machine Learning can feel overwhelming, but through trial, error, and hands-on experience, I’ve discovered a process that truly works for me. These steps have not only improved my models but also deepened my understanding of data. Here’s my personal take on feature engineering — simple, practical, and effective.</p><ol><li><strong>Handle Cardinality</strong></li></ol><p>Handling large numbers of unique values can be a major challenge in machine learning, often leading to slower training times and increased computational costs. Understanding and managing cardinality effectively is crucial for optimizing model performance (<em>Please be notified that we will sometimes use cardinality and granularity interchangeably here. Both refer to the concept of detailing level</em>).</p><p>In the ‘Handle Cardinality’ step, we aim to reduce the level cardinality as much as possible. This objective can be accomplished through two primary methods: (i) <strong>removing columns that are insignificant and exhibit excessive unique values</strong>, and (ii) <strong>aggregating or grouping values that belong to the same category to reduce complexity without sacrificing meaningful information.</strong></p><p>This becomes particularly important during the feature encoding (X) phase that follows. Encoding a column with numerous unique values, such as 25 distinct categories, can be computationally intensive and inefficient. By reducing granularity, we streamline the encoding process, thus improving the machine’s performance and efficiency.</p><p><strong>2. Split X and y</strong></p><p>We split Target and Features to instruct the machine: “<em>These columns (X) will serve as your reference for making predictions (y)</em>.” By clearly defining these two datasets, we help the machine understand their distinct roles.</p><p>This separation allows the machine to identify what input data to process (X) and what output data to predict (y).</p><p><strong>3. Split Train and Test</strong></p><p>Splitting data into Train and Test is a major step and is an inherent concept of Machine Learning. By splitting Train and Test, we assign which data that our model will learn from and which data it will be tested with.</p><p>Train data is where we feed our model the information it needs to make prediction. In simpler term, we “teach” the machine by giving it “materials” it can learn from. But since we want to test its ability now that it has learned, we use an entirely different dataset but with similar pattern.</p><p>Technically, we can split X (independent) and y (dependent) first before defining train and test. However, library <em>train_test_split</em> is designed to split X_train, X_test, y_train, and y_test simultaneously. And it needs variable X and y in its syntax.</p><p><strong>4. Handle Outliers</strong></p><p>If outliers are found to be present in the dataset, there are three ways that a Data Scientist can choose to handle them properly:</p><ul><li><strong>Remove Them:</strong> If they are irrelevant or errors. For example, we can judge that certain values are merely typo or are a mislabeling cause. We can just remove them.</li><li><strong>Cap or Floor Them:</strong> We can assign new values to our outliers if they (i) represent real-world data or if (ii) we need the values but want to avoid distortion.</li><li><strong>Retain Them:</strong> When we actually need the data to represent our analysis, it is wise to retain outliers. For example, we want to know the disparity of monthly salary in our city.</li></ul><p><strong>5. Handle Missing Values</strong></p><p>Now, there are a lot of ways of handling missing values. However, we can methodically decide what to do on these missing data by recognizing what kind of missing values are happening</p><ul><li><strong>Missing Completely at Random</strong> (MCAR)</li></ul><p>MCAR means that our data is missing without any particular reason but most importantly, <strong>it has no relationship with other data</strong>. Since it has no pattern and no relations whatsoever, we can’t perform imputation.</p><p>To handle MCaR, we can simply drop the rows with missing value. However, removing rows also has to be taken seriously. If what it entails is a huge gap in our dataset (meaning there are just too many missing values that dropping them will remove our data count significantly), then it’s advisable to have another work around.</p><ul><li><strong>Missing at Random</strong> (MAR)</li></ul><p>When I first heard the term Missing at Random, I automatically assumed that the data is just missing without any correlation to the other data, hence the random name. However, MAR is the opposite of what I initially thought of and the antithesis of MCAR. Missing at Random here means that ‘the data is missing somehow <strong>but it relates to the other variables</strong>.’</p><p>Thus, the best way to handle MAR missing values issue is to do imputation. Imputation can be done by using central tendency (mean/median/mode). For instance, if in a salary dataset we observed that a ‘salary’ column is highly related with the ‘job_title’ column, the median of salary — grouped by job title — could be a great option for imputation.</p><ul><li><strong>Missing Not at Random</strong> (MNAR)</li></ul><p>In MNAR, the missing values can be tied to itself. It can be observed that there is a specific reason tied to the data that explains why it’s missing and it’s usually that respondents simply prefer not to answer.</p><p>For instance, in a health dataset, we noticed that people tend to skip ‘current illness’ question due to privacy concern. This reaction is very understandable, but a Data Scientist needs a strategy to handle the missing information. In MNAR, we can’t simply do imputation since it may introduce inaccuracy. One way to handle these missing values is to do a follow-up survey.</p><p>However, it is important to highlight that it takes domain knowledge to recognize MNAR. For the majority of time, without having a domain knowledge or prior experience, a Data Scientist may have a difficult time identifying this problem.</p><p><strong>6. Splitting Numerical and Categorical</strong></p><p>In Machine Learning, categorical and numerical data require different preprocessing approaches. Numerical features are typically scaled using scalers, while categorical features are often encoded (we’ll cover this later on).</p><p>So, it’s only wise to split between numerical and categorical columns. Certain models, such as Linear Regression, even require input features to be in numerical form only. By splitting these two, we can have systematic way to treat each of them, based on their characteristic and needs.</p><p>It is important to note that Scientist must be aware that numerical features sometimes could be actually categorical. For example, if a column contains values like 0, 1, and 2, it’s crucial to investigate whether these represent continuous measurements or discrete categories — analyzing this distinction is key to ensuring the correct preprocessing strategy.</p><p><strong>7. Feature Selection</strong></p><p>To make it simple, Feature Selection is the process of determining which columns are essential for modeling. These columns/features (X) are selected in alignment with if they have correlation with the Target (y) or not. Although correlation with the target variable (y) is the most common criterion for selecting features (X), other methods, such as mutual information or model-based importance, can also guide the selection process.</p><p>As mentioned earlier, distinguishing between categorical and numerical variables is critical, as different techniques apply for assessing relationships. For example, ANOVA is appropriate when evaluating the relationship between numerical features and a categorical target. However, for two numerical variables, Pearson correlation is more suitable, while Chi-square tests are used for two categorical variables. Please check the graph below for more information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*OGLlYBJv4ekGxJxhwW0CMg.png" /></figure><p>Once a data scientist determines that a feature has no meaningful contribution — either individually or in combination with others — it is generally advisable to remove it to improve model efficiency without sacrificing predictive power.</p><p><strong>8. Feature Scaling</strong></p><p>Feature Scaling is usually the last few steps that is performed just before training the data. Feature scaling refers to adjusting numerical features to a similar scale to prevent one feature from dominating due to larger values.</p><p>In Machine Learning, many algorithms rely on distance-based calculations, meaning that features with larger values can disproportionately influence the results. For example, in a dataset with ‘Height’ (in cm) and ‘Price’ (in $) columns, a distance-based model may assign more importance to ‘Price’ simply because it has larger numerical values than ‘Height.’ This unintended bias can skew predictions. Therefore, scaling numerical features to a consistent range before training is essential to ensure fair contributions from all features.</p><p>The methods of scaling can be divided into three popular techniques: MinMaxScaler, StandardScaler, and RobustScaler. The choice among these depends on the presence of outliers, ranging from low tolerance (MinMaxScaler) to high tolerance (RobustScaler). Here’s a breakdown of their differences:</p><ul><li><strong>MinMaxScaler:</strong> <em>Not suitable for outliers.</em> It scales data between 0 and 1, so outliers can heavily distort the scale. <strong>Use it when data is uniformly distributed without outliers.</strong></li><li><strong>StandardScaler:</strong> <em>Tolerant to some outliers.</em> It scales data to have a mean of 0 and a standard deviation of 1. <strong>Use it when the data follows a roughly normal distribution.</strong></li><li><strong>RobustScaler:</strong> <em>Best for outliers.</em> It uses the median and IQR, making it resistant to outliers. <strong>Use it when data has many outliers.</strong></li></ul><p><strong>9. Feature Encoding</strong></p><p>To add more of Machine Learning model’s constraints, we want to highlight that many of them, especially those based on mathematical operations, require numerical input. Therefore, it is crucial to transform categorical variables into numerical representations so that they can be used in machine learning models. We call this step as ‘Feature Encoding’.</p><p>There are two common techniques for feature encoding: One-Hot Encoding and Ordinal Encoding. It is as simple as the matter that if your column is a <em>nominal categorical feature</em>, then you should use **One-Hot Encoding (**OHE). On the polar opposite, if your column is <em>ordinal categorical feature,</em> you should simply use <strong>Ordinal Encoder.</strong></p><p><strong>10. Concatenate</strong></p><p>After tedious process of engineering our features, <em>hence ‘Feature Engineering’ name</em>, we can finally concatenate or combine numerical and categorical features into one unified dataset. This is a crucial step before feeding the data into a machine learning model, as it ensures that all features are available in a single structure for training.</p><p>All in all, in my brief experience, I got to understand that Machine Learning is both an art and a science — one that becomes clearer with practice. Through these steps, I’ve not only improved my models but also gained a deeper appreciation for how data shapes predictions. If you’ve found these tips helpful or have your own techniques to share or you want to correct me, I’d love to hear from you in the comments. Let’s keep learning together — one feature at a time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d389878bee2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>