---
dataset_name: predictive_maintenance_train.csv
expiration_date: 10-10-2024
owner: tony.martin@datarobot.com
domain: time-series
title: Use anomaly detection with time series
description: This tutorial describes working with anomaly detection models in DataRobot.
url: https://docs.datarobot.com/en/tutorials/explore-ai-insights/tut-ts-anomaly-detection.html

---

# Use anomaly detection with time series {: #use-anomaly-detection-with-time-series }

Anomaly detection is a method for detecting abnormalities in data, often used in cases where there are thousands of normal transactions and only a low percentage of outliers (for example, network analysis or cybersecurity). In this tutorial, you'll learn how to interpret models that were trained to use anomaly detection (an application of unsupervised learning) to detect [time series anomalies](anomaly-detection#time-series-anomaly-detection). With unsupervised learning you do not specify a target. Instead,  DataRobot applies anomaly detection, also referred to as outlier and novelty detection, to detect abnormalities in your dataset.

## Takeaways {: #takeaways }

This tutorial explains:

- How to select the best anomaly detection model.
- How to interpret the selected model.
- Ways to deploy the anomaly detection models.

## Create an anomaly detection model {: #create-an-anomaly-detection-model }

Using the [anomaly detection workflow](anomaly-detection#anomaly-detection-workflow), select **No target** and then **Anomalies** to build an anomaly detection model.

![](images/unsup-anomaly-select.png)

Configure the [project settings](ts-flow-overview)&mdash;feature derivation windows, backtests, calendars, and any other customizations. Set a modeling mode and click **Start**.

## Select the best anomaly detection model {: #select-the-best-anomaly-detection-model }

Once Autopilot completes, examine the Leaderboard. Without a target, traditional data science metrics cannot be calculated to estimate model performance so DataRobot instead uses the [Synthetic AUC metric](anomaly-detection#synthetic-auc-metric).

### Upload an external test dataset {: #upload-an-external-test-dataset }

Synthetic AUC is a good basis for model selection if you don't have an [external test dataset](predict#make-predictions-on-an-external-dataset) available. If you *do* have an external dataset available it is better to use that. This is because the anomalies that Synthetic AUC finds may be different than the actual anomalies in your dataset.

To use an external dataset, select a model on the Leaderboard and go to [**Predict > Make Predictions**](predict).

1. [Upload](predict#make-predictions-on-an-external-dataset) an external dataset.

2. Once uploaded, click **Forecast settings**:

	![](images/tut-ts-ad-1.png)

	And then **Forecast Range Predictions**. From there, enter the name of the "known anomalies column" (to generate scores) and click **Compute predictions**.

	![](images/tut-ts-ad-2.png)

4. Once scores are computed, return to the Leaderboard and use the menu to change the display so it shows the external test column.

	![](images/external-test-menu.png)

5. In the **External test** column, click **Run** to compute scores for the other blueprints. The Leaderboard reorders results to show values sorted by the actual (not synthetic) AUC.

	![](images/tut-ts-ad-3.png)

Once the external tests are scored, click on any model to explore the visualizations.

## Explore visualizations {: #explore-visualizations }

While there are many visualizations to investigate, for anomaly-specific models some of the most important to consider are:

* [Anomaly Over Time](#anomaly-over-time-tab)
* [Anomaly Assessment](#anomaly-assessment-tab)

The following tabs are always useful for understanding your data and are described in detail in the full documentation:

* [ROC Curve tools](roc-curve-tab/index) help you understand how well the prediction distribution captures the model separation.
* [Feature Impact](feature-impact) displays the relative impact of each feature&mdash;both original and derived&mdash;on the model.
* [Feature Effects](feature-effects) show how changes to the value of each feature change model predictions in relation to the anomaly score.
* [Prediction Explanations](pred-explain/index) help you understand why a model assigned a value to a specific observation.

### Anomaly Over Time tab {: #anomaly-over-time-tab }

The [**Evaluate > Anomaly Over Time**](anom-viz#anomaly-over-time) chart helps you understand when anomalies occur across the timeline of your data. You can change the backtest being displayed to evaluate anomaly scores across specific validation periods. You can also use the chart from the [Model Comparison](model-compare) tab, which is a good method for identifying two complementary models to blend, increasing the likelihood of capturing more potential issues.

![](images/comp-anom-det-1.png)

### Anomaly Assessment tab {: #anomaly-assessment-tab }

The [Anomaly Assessment](anom-viz#anomaly-assessment) chart plots data for the selected backtest and provides [SHAP](glossary/index#shap-shapley-values) explanations for up to 500 anomalous points. It helps to identify which features are contributing to the anomaly score (via the SHAP values) and is useful for explaining high scores.

![](images/an-assess.png)

## Make predictions {: #make-predictions }

There are three mechanisms for making predictions with the selected anomaly detection model.

1. [Make Predictions tab](#make-predictions-tab)
2. [Deploy tab](#deploy-tab)
3. [Portable Prediction Server](#portable-prediction-server-pps)

### Make Predictions tab {: #make-predictions-tab }

The **Make Predictions** tab is typically used for:

* Testing from a simple Leaderboard interface.
* Small (less than 1 B) prediction datasets.
* Ad-hoc projects that don’t require frequent predictions.

	![](images/tut-ts-ad-4.png)

[Make Predictions with time series projects](ts-predictions#make-predictions-tab) works slightly differently than for non time-series projects. For time series projects, **Make Predictions** requires specific criteria for the prediction dataset and applies forecast settings.

### Deploy tab {: #deploy-tab }

Alternatively, you can create a deployment&mdash;a REST endpoint that manages prediction requests via the API. This method connects the model to a dedicated prediction server and creates a dedicated deployment object. Use the [**Deploy**](deploy-model) tab to create a deployment with the model:

1. Click **Prepare for deployment** if the model has not already been prepared.
2. [Add deployment information](deploy-model#add-deployment-information) and click **Create deployment**.

	![](images/tut-ts-ad-5.png)

3. View your deployment in the deployment [inventory](deploy-inventory).

### Portable Prediction Server (PPS) {: #portable-prediction-server-pps }

You can deploy a model via Docker with DataRobot's [Portable Prediction Server (PPS)](portable-pps). The PPS is a DataRobot execution environment for DataRobot model packages (.mlpkg files) distributed as a self-contained Docker image. Using this method moves the model closer to production data and allows you to integrate into already existing pipelines and applications.

## Learn more {: #learn-more }

- DataRobot University's [Time Series Anomaly Detection Lab](https://university.datarobot.com/anomaly-detection-lab){ target=_blank } (requires a DataRobot University subscription) to build and evaluate a time-aware unsupervised ML model to detect anomalies in a predictive maintenance dataset.

- Towards Data Science, [Anomaly Detection for Dummies](https://towardsdatascience.com/anomaly-detection-for-dummies-15f148e559c1){ target=_blank }, for an introduction to anomaly detection.


**Documentation:**

- [Time-based modeling](time/index), both out-of-time validation (OTV) and time series
- [Time series model recommendation process](ts-date-time#recommended-time-series-models)
- [**Make Predictions**](predict), full documentation (including AutoML)
- [Prediction options](predictions/index)