How to Prepare Data with a Lot of Outliers for Machine Learning

How to Prepare Data with a Lot of Outliers for Machine Learning

In the realm of machine learning, data preparation plays a crucial role in developing accurate and reliable models. However, when faced with a dataset containing a large number of outliers, the task of preparing the data becomes even more challenging.

Outliers, by their very nature, can have a significant impact on the performance of machine learning algorithms. These data points that deviate significantly from the rest of the observations in a dataset. They can arise due to various reasons such as measurement errors, data corruption, or rare events. Outliers have the potential to skew statistical summaries, distort patterns, and adversely affect the accuracy of machine learning models.

The first step in preparing data with numerous outliers is to identify and understand their nature. Several statistical techniques, such as z-score, box plots, or leverage analysis, can help identify and visualize the presence of outliers.

Once identified, it is crucial to determine whether the outliers are genuine or due to data corruption. Careful examination can help distinguish between the two and decide on an appropriate course of action.

Handling Outliers

Outlier Removal

In cases where outliers are due to data corruption or measurement errors, removing them from the dataset might be the best option. However, this approach should be exercised cautiously, as it can lead to loss of valuable information. Outliers should only be removed after careful consideration and domain knowledge.


Winsorization is a technique that replaces extreme values with values closer to the mean or median. It involves setting a threshold beyond which any data point is replaced with the value at that threshold. This technique helps mitigate the impact of outliers while preserving the overall distribution of the data.


Transforming the data using mathematical functions can help normalize the distribution and reduce the impact of outliers. Common transformations include taking logarithms, square roots, or reciprocals. These transformations can help make the data more amenable to machine learning algorithms, diminishing the influence of outliers.


Binning involves dividing the data into intervals and replacing each data point with the interval mean or median. This technique can help group outliers with nearby observations, reducing their individual impact. However, it is essential to choose appropriate bin sizes to prevent oversimplification of the data.

Robust Algorithms

Another approach to handling data with numerous outliers is to use robust machine learning algorithms. These algorithms are designed to be less influenced by outliers and can provide more accurate results. Robust algorithms include Support Vector Machines (SVM), Random Forests, or Gradient Boosting.

The link below will take you to the code for my work on one dataset that was just teeming with outliers. By the way, the preview picture for this blog is taken from this study. And it was a very interesting experience that I spent several hours on.


Leave a Reply

Your email address will not be published. Required fields are marked *