Univariate Anomaly Detection - Historical Data and Latest Data

Learn to build and perform anomaly detection on univariate data using the Azure Anomaly Detectors.

What is univariate anomaly detection?

The univariate anomaly detection is the simplest form of anomaly detection where the machine learning algorithm needs to learn only a single feature space. This means that there is a single feature value associated with the timestamp. For example, to determine the anomalies in the incomes of people living in the United States we would need only one feature—the income itself.

Dependencies

To work with this chapter and run the code snippets on your local machine, you would need the following package to be installed:

  • azure-ai-anomalydetector

To know how to install the required package, please visit the Appendix section.

Implementation

To properly cover univariate anomaly detection, we’ll perform three types of detection:

  • Detecting the anomalies in the historical data set: We’ll use time-series data and convert it into a list of TimeSeriesPoint. This is a class from the anomaly detector Python SDK. It accepts the timestamp and the value (for example, temperature, humidity, or any other type of value that needs to be monitored for anomalies). Then, we need to create a DetectRequest object and pass it to the detect_entire_series() method that will call the anomaly detector and return the anomalies identified in the data.

  • Detecting an anomaly in the latest data point: We’ll use the same DetectRequest object and then call the detect_last_point() method to check the anomaly for the latest point based on the timestamp.

  • Detecting the change points in the time-series data: We’ll use the same DetectRequest object and then call the detect_change_point() method to get the change points from the data.

    The change point in time-series data is an unexpected behavior in the data pattern that is normal and not considered as an anomaly.

Detecting anomalies in the historical data set

Let’s begin with detecting the anomalies in the complete time-series data. Here, we’ll be using sample data consisting of the stock price of a company. The data consists of two values i.e., the timestamp and the stock price in USD. By using the azure anomaly detector, we would be able to determine at which day the stock price went unusual (considering that it is a linear increase in stock price).

Get hands-on with 1400+ tech skills courses.