<@U088WCP3B4P> How can I exclude a period from ano...
# ask-elementary-ai
f
@kapa.ai How can I exclude a period from anomaly detection?
k
A message from kapa.ai
To exclude a specific period (such as "today" or the latest incomplete time bucket) from anomaly detection in Elementary Data, you should use the detection_delay parameter. This parameter allows you to specify a delay period, so the most recent data (which may be incomplete or not yet fully loaded) is ignored by the anomaly detection tests. Here’s how you can configure it:
Copy code
yaml models:   - name: your_model_name     tests:       - elementary.volume_anomalies:           detection_delay:             period: day             count: 1
- period: The time unit to delay (e.g., hour, day, week, month). - count: The number of periods to delay. This configuration will exclude the most recent day from anomaly detection, which is useful if your data for the current day is not yet complete or fully loaded. The detection_delay parameter only works for tests that have a timestamp_column configured and does not affect other duration parameters like detection_period or training_period. The default value is 0 (no delay) [Detection Delay Documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/detection-delay). If you need to exclude specific values or periods in a more granular way, you can use the anomaly_exclude_metrics parameter with a SQL expression, but this requires explicitly specifying the cases to exclude [Anomaly Params](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/anomaly-params). For most use cases where you want to ignore the latest period (e.g., "today"), detection_delay is the recommended approach.
f
Can I exclude dates for some dimensions ?
@kapa.ai Can I exclude dates for some dimensions ?
k
A message from kapa.ai
Yes, you can exclude specific dates for some dimensions in Elementary anomaly detection tests by using the anomaly_exclude_metrics parameter. This parameter allows you to provide a SQL where expression to filter out certain data points from the training set, and you can use it to target specific dates and dimensions. For example, you can write an expression like:
Copy code
yaml models:   - name: your_model     tests:       - elementary.volume_anomalies:           anomaly_exclude_metrics: "metric_date = '2024-07-04' AND dimension_value = 'US'"
This would exclude July 4th for the dimension value 'US' from the anomaly detection training set. You can adjust the SQL expression to match your specific use case and dimensions. The filter can be configured using fields like metric_date, metric_time_bucket, and metric_value, and is supported in all anomaly detection tests [anomaly_exclude_metrics documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/anomaly-exclude-metrics). Keep in mind that you need to specify the correct dimension field in your expression, and this approach requires you to enumerate the dates and dimensions you want to exclude. There is currently no built-in feature to exclude dates for dimensions via a calendar table, but you can use SQL logic in anomaly_exclude_metrics to achieve similar results.