<@U088WCP3B4P> How to set training period for a tr...
# ask-elementary-ai
n
@kapa.ai How to set training period for a truncate and load table volume anomaly test. Also how to set detection period for the same?
k
A message from kapa.ai
To set the training period and detection period for a volume anomaly test on a truncate-and-load table in Elementary, you should configure these parameters in your test YAML. The approach depends on whether you use a `timestamp_column`: ### 1. Without a
timestamp_column
(typical for truncate-and-load tables) - The test tracks the total row count each time it runs, not per time bucket. - The training period is built up over multiple test runs (e.g., 14 runs for a 14-day training period). - Configure the test like this:
Copy code
yaml tests:   - elementary.volume_anomalies:       training_period: 14   # Number of test runs to use as training set       detection_period: 2   # Number of most recent runs to check for anomalies
- Note: You must run the test enough times to build up the training set. For a 14-day training period, you need 14 runs on different days before anomaly detection is possible. Each run adds a new data point to the training set. The detection period defines how many recent runs are checked for anomalies. [Anomaly Tests Troubleshooting Guide](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/Anomaly-troubleshooting-guide) ### 2. With a
timestamp_column
- If you can use a timestamp column (e.g., a load date), Elementary will group data into time buckets (e.g., daily). - Configure the test like this:
Copy code
yaml tests:   - elementary.volume_anomalies:       timestamp_column: <your_timestamp_column>       training_period:         period: day         count: 14       detection_period:         period: day         count: 2       time_bucket:         period: day         count: 1
- Here, the training period uses the last 14 days (or whatever period you set), and the detection period checks the last 2 days for anomalies. [training_period docs](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/training-period) | [detection_period docs](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/detection-period) ### Key Points - For truncate-and-load tables, if you do not have a timestamp column, the training and detection periods are based on the number of test runs, not calendar days. - If you do have a timestamp column, periods are based on the data in those time buckets. - You must run the test enough times to build up the training set if not using a timestamp column. If you need to monitor the entire table's row count after each load, do not set a timestamp column. If you want to monitor by date or another time dimension, set the
timestamp_column
accordingly. For more details, see the official documentation on [volume_anomalies test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/volume-anomalies#test-configuration) and [training_period](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/training-period).
n
And how to set detection period?
@kapa.ai and how to set detection period for truncate and load tables?
k
A message from kapa.ai
For truncate-and-load tables without a
timestamp_column
, the detection period in Elementary's volume anomaly test is set using the
backfill_days
parameter. This parameter defines how many recent test runs (not calendar days) are included in the detection period for anomaly detection. You can configure it in your test YAML like this:
Copy code
yaml tests:   - elementary.volume_anomalies:       backfill_days: 2  # Number of most recent runs to include in the detection period
- For tables without a timestamp column,
backfill_days
is used only as the detection period. Each test run adds a new data point, and the detection period will include the specified number of most recent runs. - There is no time bucketing; the detection period is simply the last N runs, as defined by
backfill_days
 [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1688112798629339). Note: The
detection_period
parameter is only relevant for tests with a
timestamp_column
. For truncate-and-load tables without a timestamp column, use
backfill_days
to control the detection period [Detection period docs](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/detection-period). If you need to skip anomaly detection for a while (e.g., after a structural change), you can increase
backfill_days
or temporarily disable the test [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1683560936330689).