### Introduction

Imagine, you are working hard and very carefully while collecting important data. Suddenly, you come across some bad data in your calculation and the whole job gets awry. These errors are called ?outliers? in machine learning - something that everyone, especially data scientists finds very frustrating. Outliers in machine learning are harmful to the data collection process and can distort your observations. It is important to detect and get rid of these outliers beforehand. This is what we are going to learn in this article.

### What are Outliers in Machine Learning?

An outlier is a data point that stands out from the rest. They reflect measurement mistakes, poor data collection, or simply variables that were not considered when collecting the data. According to Wikipedia, it is a ?distant observation location from other observations.' Outliers have the potential to distort your results and provide incorrect information.

### What are the Different Types of Outliers?

Point Outliers

Anomalies in comparison to the bulk of observations in a feature. In a nutshell, a data point is called a global outlier if its value falls significantly outside the bounds of the data collection in which it is discovered.

### Contextual Outliers

Anomalies are observations that are deemed unusual in a certain situation. A data point is called a contextual outlier if its value deviates considerably from that of the other data points in the same context. It is important to note that the same result may not be deemed an outlier if it occurs in a different environment. Because time series data are records of a certain amount across time, the "context" is nearly always temporal. It should come as no surprise that contextual outliers are prevalent in time series data. Contextual Anomaly levels are not outside of the usual global range but are out of the seasonal rhythm.

### Collective Outliers

A group of anomalous observations that look near to one another due to their comparable abnormal value.

A subset of data points within a data set is deemed anomalous if their values as a group deviate considerably from the overall data set, but the individual data points' values are not abnormal in either a contextual or global sense. In time-series data, this might appear as typical peaks and valleys happening outside of a time period when the seasonal sequence is normal, or as a collection of time series that are in an outlier condition.

### What Causes Outliers in Machine learning?

The following are the most typical sources of outliers in a data set:

**Errors in data entry: **Outliers in data can be produced by human mistakes such as those made during data collection, recording, or input.

**Error in measurement:** Outliers are most commonly found in this context. This occurs when the measurement instrument employed is found to be defective.

**Errors in experimental design** (data extraction or experiment planning/execution)

**On purpose **(dummy outliers made to test detection methods)

**Errors in data processing**

**Errors in sampling**

**Natural outlier **(data novelty, not an error): When an outlier is not caused by a human mistake, it is referred to as a natural outlier. This category contains the majority of real-world data.

### How to Get Rid of Outliers in Machine Learning?

Outliers cannot be identified when collecting data; you will not know which numbers are outliers until you begin analyzing the data. Many statistical tests are sensitive to outliers, thus being able to detect them is a crucial component of data analytics. The interpretability of an outlier model is critical because choices aimed at dealing with an outlier require some context or explanation.

In reality, outliers can be useful indications at times. Outlier analysis, for example, becomes essential in some data analytics applications, such as credit card fraud detection, since the analyst may be interested in the exception rather than the rule. Simply said, when you identify outliers, you have three options: accept them, rectify them, or remove them. If there is a probability that the outlier will not have a substantial impact on the outcome, you may choose to "accept" it. Otherwise, you have the option of ?correcting' it or deleting it. However, you should only delete data points that are clearly incorrect.

So, here are some ways in which outliers can be removed from machine learning:

### Observation Deletion

To avoid skewing your research, it is sometimes advisable to delete certain entries entirely from your dataset. We remove outlier values if they are the result of a data input error, a data processing error, or if the number of outlier observations is very tiny. Trimming at both ends can also be used to remove outliers. However, when we have a tiny dataset, removing the observation is not a smart idea.

### Value Transformation

Outliers can be eliminated by transforming variables. The variance produced by extreme values is reduced by these modified values.**Log transformation****Scaling**

B**ox-transformation****Normalization of cube roots**

These approaches reduce the size of the dataset's values. If your data has too many extreme values or is skewed, this approach can help you normalise it. However, these methods do not always produce the greatest outcomes. These approaches result in no data loss. In all of these methods, the box cox transformation produces the best results.

### Imputation

We can impute outliers in the same way that we may impute missing numbers. In this approach, we may utilise the mean, median, and zero value. There is no data loss because we are imputing. In this case, the median is suitable since it is unaffected by outliers.

### Separately Treating

If there are a large number of outliers and the dataset is tiny, we should consider them individually in the statistical model. One method is to consider both groups as separate entities, construct distinct models for each, and then merge the results. However, when the dataset is huge, this approach becomes laborious.

## Conclusion

Getting a sudden error while writing or executing a code can be heavily frustrating. Outliers when show up, act like a bug for your hard drafted code. It can be a mood killer when you are coding for 6 or 7 hours straight and then they show up.

These were the ways how one can remove outliers from machine learning. Hope now you know the concept of outliers. Outliers are a part of every machine learning program, but they need to be identified and removed. So, now that you know how to do the same, happy coding.