> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elementary-data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# training_period

<Card title="Generate your anomaly test with Elementary AI" icon="wand-magic-sparkles" horizontal="true" href="https://elementary-data.com/community">
  Let our Slack chatbot create the anomaly test you need.
</Card>

```
training_period:
  period: < time period > # supported periods: day, week, month
  count: < number of periods >
```

The maximal timeframe for which the test will collect data.
This timeframe includes the training period and detection period. If a detection delay is defined, the whole training period is being delayed.

* *Default: 14 days*
* *Relevant tests: Anomaly detection tests with `timestamp_column`*

<img src="https://mintcdn.com/elementary/hSCs0_UCmzxCQWF5/pics/anomalies/training-period.png?fit=max&auto=format&n=hSCs0_UCmzxCQWF5&q=85&s=1d2d7f7680e5c59d455d1f45a3bed02d" alt="Training Period" width="2026" height="2058" data-path="pics/anomalies/training-period.png" />

<RequestExample>
  ```yml test theme={null}
  models:
    - name: this_is_a_model
      data_tests:
        - elementary.volume_anomalies:
            arguments:
              training_period:
                period: day
                count: 30
  ```

  ```yml model theme={null}
  models:
    - name: this_is_a_model
      config:
        elementary:
          detection_delay:
            period: week
            count: 1
  ```

  ```yml dbt_project.yml theme={null}
  vars:
    detection_delay:
      period: month
      count: 1
  ```
</RequestExample>

#### How it works?

The `training_period` param only works for tests that have `timestamp_column` configuration.

It works differently according to the table materialization:

* **Regular tables and views** - The values of the full `training_period` period is calculated on each run.
* **Incremental models and sources** - The values of the full `training_period` period is calculated on the first test run, and on full refresh. The following test runs will only calculate the values of the `detection_period` period.

**Changes from default:**

* **Full time buckets** - Elementary will increase the `training_period` automatically to insure full time buckets. For example if the `time_bucket` of the test is `period: week`, and 14 days `training_period` result in Tuesday, the test will collect 2 more days back to complete a week (starting on Sunday).
* **Seasonality training set** - If seasonality is configured, Elementary will increase the `training_period` automatically to ensure there are enough training set values to calculate an anomaly. For example if the `seasonality` of the test is `day_of_week`, `training_period` will be increased to ensure enough Sundays, Mondays, Tuesdays, etc. to calculate an anomaly for each.

**Overlap with detection period:**

When the `detection_period` spans multiple time buckets, it can overlap with the training period. By default, values in the detection period are included in the training calculation, which can lead to false negatives because detection period values influence the expected range used to evaluate those same values. To prevent this overlap and improve anomaly detection accuracy, use [`exclude_detection_period_from_training`](/data-tests/anomaly-detection-configuration/exclude_detection_period_from_training) set to `true`.

#### The impact of changing `training_period`

If you **increase `training_period`** your test training set will be larger. This means a larger sample size for calculating the expected range, which should make the test less sensitive to outliers. This means less chance of false positive anomalies, but also less sensitivity so anomalies have a higher threshold.

If you **decrease `training_period`** your test training set will be smaller. This means a smaller sample size for calculating the expected range, which might make the test more sensitive to outliers. This means more chance of false positive anomalies, but also more sensitivity as anomalies have a lower threshold.
