<?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 Suryanshrana on Medium]]></title>
        <description><![CDATA[Stories by Suryanshrana on Medium]]></description>
        <link>https://medium.com/@suryanshrana91?source=rss-5dd2531a4679------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qTuLj9knAv_NRI5Licod5A.png</url>
            <title>Stories by Suryanshrana on Medium</title>
            <link>https://medium.com/@suryanshrana91?source=rss-5dd2531a4679------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 13:41:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@suryanshrana91/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[What is Feature Engineering?]]></title>
            <link>https://medium.com/@suryanshrana91/a-beginners-guide-to-feature-engineering-for-machine-learning-e4d2bf9cb4b4?source=rss-5dd2531a4679------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4d2bf9cb4b4</guid>
            <category><![CDATA[handling-missing-values]]></category>
            <category><![CDATA[eda]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <dc:creator><![CDATA[Suryanshrana]]></dc:creator>
            <pubDate>Fri, 08 Nov 2024 14:46:45 GMT</pubDate>
            <atom:updated>2024-11-14T07:05:49.079Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is Feature Engineering?</strong></p><p>Feature engineering is the process of transforming raw data into features that better represent the underlying patterns to the machine learning model, which can improve its performance and predictive accuracy. It involves creating new features, modifying existing ones, and selecting the most important features in a dataset to help the model learn more effectively.</p><p><strong>Why is Feature Engineering Important?</strong></p><p>Feature engineering is crucial because it directly impacts the effectiveness of a machine learning model. High-quality features can simplify the learning task for the model, leading to faster training times and better performance. In summary, feature engineering is about making data more meaningful and accessible to machine learning algorithms, helping them to learn the patterns in the data more effectively and accurately.</p><h3>Key Aspects</h3><ol><li>Handling Missing Values</li><li>Encoding Categorical Variables</li><li>Dealing with Imbalanced Data</li></ol><p>When working with real-world data, it’s common to encounter challenges like missing values, categorical variables that need encoding, and imbalanced datasets. Here’s a breakdown of each issue and some popular techniques to handle them effectively.</p><h4>1. Handling Missing Values</h4><p>Missing data is a frequent issue in datasets, and how you handle it can significantly impact your model’s performance.</p><p>When dealing with missing data, it’s essential to understand the types of missingness, as each type requires different handling strategies.</p><ol><li><strong>MCAR (Missing Completely at Random)</strong></li></ol><p>Data is missing completely at random if the probability of a data point being missing is independent of both observed and unobserved data. When data is <strong>MCAR</strong>, there is no systematic reason for its absence. This means that the missingness occurs randomly and is unrelated to any other variable in the dataset (either observed or unobserved).</p><p>2.<strong> MAR (Missing at Random)</strong></p><p>Data is missing at random if the probability of missingness is related to observed data but not to the missing data itself. For example, if survey responses about income are missing mostly for younger people, then the missingness is related to age (an observed variable), but it doesn’t depend on income itself. This type of missingness has a pattern, but it’s based on other known factors.</p><p>3. <strong>MNAR (Missing Not at Random)</strong></p><p>Data is missing not at random if the probability of missingness is related to the unobserved data itself. For example, in a health survey, people with severe health issues might choose not to answer questions about their health. Here, the missingness is related to the sensitive nature of the health information itself.</p><h4><strong>Handling Missing Values</strong></h4><h4><strong>1. Imputation Methods</strong></h4><ol><li><strong>Mean Imputation</strong>: Replaces missing values with the mean (average) of the non-missing values in the column. Suitable for continuous data that’s <strong>Normally distributed</strong> but can be affected by outliers.</li></ol><pre>import seaborn as sns<br>df=sns.load_dataset(&quot;titanic&quot;)<br># distribution plot<br>sns.displot(df[&quot;age&quot;],kde=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*JFFT5FKWz37RnbDbN4hQvQ.png" /><figcaption>It resembles a normal distribution — not perfectly, but somewhat close.</figcaption></figure><pre>df[&#39;Age_mean&#39;]=df[&#39;age&#39;].fillna(df[&#39;age&#39;].mean()) # code sample</pre><p><strong>2. Median Value Imputation</strong></p><p>Fills missing values with the median (middle value) of the column. This method is more robust than mean imputation, especially for data with <strong>skewed distributions or outliers</strong>, since the median isn’t affected by extreme values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*lTPjEryyXOmXnZxo0DCYaA.png" /><figcaption>Skewed Distribution</figcaption></figure><pre>df[&#39;Age_median&#39;] = df[&#39;age&#39;].fillna(df[&#39;age&#39;].median()) #example of code</pre><p><strong>3. Mode Imputation</strong></p><p>Replaces missing values with the mode (most frequent value) in the column. This is typically used for <strong>categorical data</strong>, where it can help maintain the most common category in the dataset.</p><pre>import seaborn as sns<br>df=sns.load_dataset(&quot;titanic&quot;)<br>mode_value=df[df[&#39;embarked&#39;].notna()][&#39;embarked&#39;].mode()[0]<br>df[&#39;embarked_mode&#39;] = df[&#39;embarked&#39;].fillna(mode_value)</pre><h4><strong>2. Handling Imbalanced Datasets</strong></h4><p>Handling imbalanced datasets refers to addressing the issue that occurs when the classes in a dataset are not represented equally. This is common in classification tasks where one class (typically the minority class) has far fewer instances than the other (majority class). Imbalance can lead to biased models that are more likely to predict the majority class, making the model less effective for detecting the minority class.</p><p><strong>Resampling Techniques</strong></p><ol><li><strong>Up-sampling (Over-sampling)</strong></li></ol><p><strong>Up-sampling</strong> refers to increasing the number of instances in the <strong>minority class</strong> to balance the dataset.</p><p><strong>2. Down-sampling (Under-sampling)</strong></p><p><strong>Down-sampling</strong> involves reducing the number of instances in the <strong>majority class</strong> to balance the dataset.</p><p>To explore the topic of <strong>Handling Imbalanced Datasets</strong>, you can follow this link to view the full explanation and code examples</p><p><a href="https://github.com/ranasuryansh14/Feature_Engineering/blob/main/Feature%20Engineering/Handling_Imbalanced_dataset.ipynb">Feature_Engineering/Feature Engineering/Handling_Imbalanced_dataset.ipynb at main · ranasuryansh14/Feature_Engineering</a></p><h4><strong>SMOTE</strong> (Synthetic Minority Over-sampling Technique)</h4><p>is an oversampling technique used to handle <strong>imbalanced datasets</strong> in machine learning. It generates synthetic examples for the <strong>minority class</strong> by creating new samples that are combinations of existing minority class instances. This helps to balance the dataset by making the minority class larger and more diverse.</p><p>Basically it generates synthetic instances of the minority class by interpolating between existing instances</p><p>A <strong>scatter plot</strong> of the dataset is created showing the large mass of points that belong to the majority class (Violet) and a small number of points spread out for the minority class (Yellow). We can see some measure of overlap between the two classes.</p><p>Scatter Plot of Imbalanced Dataset</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*-3Y4KpSa2UhYEgMmZ7UJSw.png" /></figure><p>Scatter Plot After SMOTE (Oversampling)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*ChUwHTFNhV5iWYYuO4azOA.png" /></figure><p>To explore SMOTE, you can follow this link to view the full explanation and code examples</p><p><a href="https://github.com/ranasuryansh14/Feature_Engineering/blob/main/Feature%20Engineering/Smote_tech.ipynb">Feature_Engineering/Feature Engineering/Smote_tech.ipynb at main · ranasuryansh14/Feature_Engineering</a></p><h4><strong>3. Data encoding</strong></h4><p>It is the process of converting categorical or non-numeric data into a numerical format so that it can be used by machine learning algorithms, which typically require numerical input. There are several techniques for encoding data, and the choice of method depends on the nature of the data and the machine learning model being used.</p><ul><li>One-Hot Encoding</li><li>Label Encoding</li><li>Ordinal Encoding</li><li>Target Encoding</li></ul><h4><strong>1. Nominal / </strong>One-Hot Encoding</h4><p>One hot encoding, also known as <strong>nominal encoding</strong>, is a technique used to represent categorical data as numerical data, which is more suitable for machine learning algorithms. In this technique, each category is represented as a binary vector where each bit corresponds to a unique category. For example, if we have a categorical variable “color” with three possible values (red, green, blue), we can represent it using one hot encoding as follows:</p><p>1. Red: [1, 0, 0]</p><p>2. Green: [0, 1, 0]</p><p>3. Blue: [0, 0, 1]</p><h4>2. Label Encoding</h4><p>Label encoding and ordinal encoding are two techniques used to encode categorical data as numerical data. Label encoding involves assigning a unique numerical label to each category in the variable. The labels are usually assigned in alphabetical order or based on the frequency of the categories. For example, if we have a categorical variable “color” with three possible values (red, green, blue), we can represent it using label encoding as follows:</p><p>1. Red: 1</p><p>2. Green: 2</p><p>3. Blue: 3</p><h4>3. Ordinal Encoding</h4><p>It is used to encode categorical data that have an intrinsic order or ranking. In this technique, each category is assigned a numerical value based on its position in the order. For example, if we have a categorical variable “education level” with four possible values (high school, college, graduate, post-graduate), we can represent it using ordinal encoding as follows:</p><p>1. High school: 1</p><p>2. College: 2</p><p>3. Graduate: 3</p><p>4. Post-graduate: 4</p><h4>4. <strong>Target Guided Ordinal Encoding</strong></h4><p>It is a technique used to encode categorical variables based on their relationship with the target variable. This encoding technique is useful when we have a categorical variable with a large number of unique categories, and we want to use this variable as a feature in our machine learning model. In Target Guided Ordinal Encoding, we replace each category in the categorical variable with a numerical value based on the mean or median of the target variable for that category. This creates a monotonic relationship between the categorical variable and the target variable, which can improve the predictive power of our model.</p><p><a href="https://github.com/ranasuryansh14/Feature_Engineering/blob/main/Feature%20Engineering/Nominal_OHE.ipynb">Feature_Engineering/Feature Engineering/Nominal_OHE.ipynb at main · ranasuryansh14/Feature_Engineering</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4d2bf9cb4b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>