Add Exogenous Variables to Anomaly Detection
Learn how to improve anomaly detection by incorporating external factors.
Overview
Detecting anomalies in time series data can be enhanced by using additional external (or exogenous) features. Here, you’ll learn how to include exogenous variables in your anomaly detection workflow using Nixtla.
Key Benefits
-
Leverage additional context from exogenous features
-
Boost anomaly detection accuracy
-
Flexible usage via Azure AI or the public API
Including relevant exogenous variables can greatly improve anomaly detection, especially for time series influenced by external factors such as weather or market indicators.
Load Dependencies
Use the following code to import the necessary libraries and create a Nixtla client instance:
(Optional) Configure Azure AI
If you want to use an Azure AI endpoint, set the base URL and optional Azure-specific parameters:
You can configure an Azure AI endpoint by specifying the base_url and your api_key.
Load and Inspect Data
Read and inspect your dataset, ensuring that it contains the exogenous features as additional columns:
Detect Anomalies with Exogenous Features
Use the detect_anomalies method to identify anomalies, automatically detecting which columns are exogenous features:
By default, the method will infer freq (data frequency) and exogenous columns automatically.
Visualize Anomalies
Detected anomalies in time series with exogenous variables
Inspect Model Weights (Optional)
View the relative weights of the exogenous features to understand their impact:
Weights of exogenous date features
For more detailed guidance on anomaly detection, including best practices and troubleshooting tips, see the Anomaly Detection Guide
Continue exploring with the NixtlaClient methods for more advanced configurations and optimizations.