Top Five Methods to Identify Outliers in Data

Mark Taylor
The Startup
Published in
5 min readDec 15, 2020

Identifying outliers is important for every data scientist. It helps detect abnormal data points or data that do not fit in the right pattern.

Outliers — the twisted tale of data!

But what is an outlier?

As defined by Wikipedia, “an outlier is a data point that differs significantly from other observations. An outlier may be due to variability in the measurement or it may indicate the experimental error; the latter are sometimes excluded from the data set. An outlier can cause serious problems in statistical analyses.”

Outliers can also be referred to as observations that are unlike any other observations. They are certain data points that do not belong in a specific population. Such observations are often abnormal and lie stranded from other values. An outlier is a data which is inherently different as compared to the other data, also termed as anomalies.

For instance,

[24, 27, 19, 28, 1300, 20, 18]

You can easily identify the outlier from the above figures, right? Well, if it is just a bunch of numbers, identifying outliers can be easy, but tough when there are thousands of multi-dimensions. You will need to streamline the methods to detect anomalies in those cases.

An outlier affects the efficiency of every model, thus influencing the model’s performance. This is one major reason why it is highly important to remove outliers or anomalies in a dataset.

👉Anomalies/outliers, should we care?

Well, with data growing at a rapid pace, it has made us rethink the way we can approach these anomalies. With the spread of the Internet of Things (IoT) devices, it is going to be even more challenging.

Here’s an example, most people use smartwatches to keep track of their heartbeat every second. If there’s a way we can detect an anomaly in the data produced by the heartbeat, it can be easily used in predicting heart disease.

In traffic, they could be used to prevent accidents.

Is there a way to deal with outliers in Python?

Yes, there is a way to detect outliers in Python.

In the first step, you need to import the library (NumPy and Pandas) are two models crucial in this step. Then followed by creating a DataFrame. The data frame must be empty named “xyz”. Once this is created, you can add the feature and values to it.

Detecting outliers in Python requires you to know methods such as:

· Rescaling the data

· Marking the outliers

· Dropping outliers

Well, these were methods to detect an outlier in Python.

Let us further delve deeper and explore the other common and simplest methods used in identifying outliers in the dataset.

👉Boxplots

Boxplot is a graphical representation of numerical data depicted through their quartiles or quantiles. It is a simple yet highly effective method to detect any anomaly or outlier.

Take the lower and upper whisker to be the boundary of the data distribution. Now any data that is seen below the lower whisker or upper whisker is considered an anomaly.

The anatomy of boxplots works on the concept of the Interquartile Range (IQR), making it possible to build boxplot graphs. The IQR holds strong significance in identifying outliers.

👉Robust Random Cut Forest

Tech giant Amazon uses the “Robust Random Cut Forest” algorithm to detect an outlier or any type of anomaly.

The algorithm functions by going through an anomaly score. An indication of a low score means the data point as normal. However, if the score is on a higher level, it indicates the presence of an anomaly.

The low and high score truly depends upon the application, but common practices always suggest a score that goes above three standard deviations from the mean score is definitely an anomaly. An even interesting fact about this algorithm is that it works well with even high dimensional data, offline data, and real-time streaming data.

👉Isolation Forest

The Isolation Forest uses the unsupervised machine learning algorithm belonging to the ensemble decision tree family.

The methods used in this approach is different from the other methods. Most of the methods first tried to identify the normal region of the data then moved forward to identifying anything that seemed out of place.

However, with isolation forest, things are different.

The approach used here first separates the anomalies rather than profiling normal regions. An added advantage, this method works best with high dimensional data and is proven highly effective.

👉Standard Deviation

Perhaps we all know how standard deviation works. For instance, when the data distribution is normal, around 68 percent of the data value is said to lie within one standard deviation of the mean, while 95 percent happens to be within two standard deviations, and 99.7 percent within three standard deviations.

Thus, having any data point which is three times more than the standard deviation, then those points can be identified as outliers.

👉DBScan Clustering

The name of the method itself denotes that this approach involves a clustering algorithm. The algorithm is used in identifying outliers using a density-based anomaly detection method. This method is ideal for both single and multi-dimensional data.

Some of the other clustering algorithms used to detect anomalies include names like hierarchal clustering and k-means.

DBScan strictly follows three crucial concepts –

  • Core points — to understand this concept, you first need to know the hyperparameters used in defining DBScan job i.e. [HP] min_samples (for a minimum number of core points require to form a cluster) and [HP] eps. eps (for the maximum distance between two samples required to form a cluster).
  • Border points — almost similar cluster as the core points but much farther from the center of the cluster.
  • Noise points — any data point that does not belong to any type of cluster can be called noise points. This can either be anomalous or non-anomalous, however, further investigation would be highly required.

Outliers indicate bad data. Therefore, for you to obtain actionable insights and make the right prediction, detecting anomalies and outliers is crucial for every data scientist. Bad data can mess up your prediction.

--

--

Mark Taylor
The Startup

Professional data scientist, Data Enthusiast. #DataScience #BigData #AI #MachineLearning #Blockchain