Hello Everyone!!!! The most important phase in Feature Engineering is handling outliers because it ensures that our model is trained on accurate data which leads to accurate models.
Today we’ll look at what outliers are, their causes and consequences, various ways to identifying them, and finally various methods for dealing with them using code samples.
The code sample and dataset for this article are available here.
A data point that varies greatly from other results is referred to as an outlier.
An outlier may alsobe described as an observation in our data that is incorrect or abnormal as compared to other observations.
Outliers can be caused by measurement uncertainty or due to experimental error.
Outliers in data can spoil and deceive the training process of machine learning models, resulting in less accurate models and eventually bad performance.
Now that we know what outliers are and how they affect Machine Learning algorithms, let’s look at how we can detect them in our data.
Outliers in data can be observed using a number of techniques. In this article, we’ll look at the most popular method, which is the visualization technique.
To find outliers, we can simply plot the box plot. Outliers are points that are outside of the minimum and maximum values, as seen in the image below.
How to Measure the Outliers
We can measure the boundary for outliers once we’ve decided whether outliers are present in the data using the box plot. To measure the boundary for outliers, we can use the two methods below, both based on data distribution.
I) If the Data is Normally Distributed
We can use the empirical formula of Normal Distribution to determine the boundary for outliers if the data is normally distributed.
Let’s have a look at the below code to find the outliers boundaries for our dataset:
II) If the Data is Either Right Skewed or Left Skewed
We will use the Interquartile Range to measure the limits of Outliers if the data doesn’t follow a Normal Distribution or is either right-skewed or left-skewed.
The formula for the outlier boundary can be calculated as:
If the outlier’s maximum value is extremely high in comparison to the upper boundary, the boundary of outliers (also known as extreme outliers) will be calculated using the formula below:
Let’s have a look at the below code to find the outliers boundaries for Fare Column:
Following approaches can be used to deal with outliers once we’ve defined the boundaries for them:
We may explicitly delete outlier observation entries from our data so that they don’t influence the training of our models. When dealing with a small dataset, however, eliminating the observations is not a good idea.
To impute the outliers, we can use a variety of imputation values, ensuring that no data is lost. As impute values, we can choose between the mean, median, mode, and boundary values.
Congratulations on learning how to deal with outliers while doing Feature Engineering on the data.
Thank you for taking the time to read this post. If you liked this read, hit the ???? button and share it with others. You can also check other interesting articles under my Medium profile. If any questions, please leave them in the comments section and I will do my best to answer them.
You can connect with me on LinkedIn, Facebook, and Instagram.