# seasonality

## Usage

{% hint style="info" %}
Allows to **extract seasonality** for different date attributes from **training** data basing on column to pedict
{% endhint %}

This calculator can be used with the following method:

<mark style="color:red;">**`seasonality`**</mark>

Examples:

* Extract week/month seasanalities coefficients from sales history

***

## Main Parameters

{% hint style="success" %}
**The bold options** represent the default values when the parameters are optional.
{% endhint %}

* *<mark style="color:blue;">input\_columns</mark>* \
  list of columns used as input of the calculators
* *<mark style="color:blue;">output\_columns</mark>* \
  list of columns added by the calculators
* *<mark style="color:blue;">global</mark>* *(true, **false)*** \
  Should this calculator be performed before data splitting during training for cross-validation
* *<mark style="color:blue;">steps</mark>* \[optionnal] *(**training, prediction**, postprocessing*)\
  List of steps in a pipeline where columns from this calculator are added to the data. Note that when the training option is listed, the calculator is actually added during preprocessing.
* *<mark style="color:blue;">store\_in\_model</mark>* \[optionnal] *(true, **false)*** \
  Please indicate whether the "calculated" columns by the calculator should be stored in the model or not to avoid recalculating them during prediction. This is only relevant if the calculated columns are added to both training and prediction. Without this parameter, the values will not be stored in the model. The following parameters only make sense if this parameter is set to *true*.
* *<mark style="color:blue;">stored\_columns</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to be stored among the *<mark style="color:blue;">output\_columns</mark>*.
* *<mark style="color:blue;">stored\_keys</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to use for identifying the correct values to join on the data for prediction among the stored values (logically, they are to be chosen from the *<mark style="color:blue;">input\_columns</mark>*).

***

## Specific Parameters

* *<mark style="color:blue;">value</mark>*\
  Name of the column to use for extracting seasonality
* *<mark style="color:blue;">time\_col</mark>*\
  Name of the column that contains time

***

## Examples

1. We want to capture additional weekly effects on sales. The `month` column is calculated from the `date_attribute`. `Store_in_model` is used because the weekly seasonality coefficient will be computed during training and applied during prediction.

   ```yaml
   calculated_cols:
     month_coefficient:
       method: seasonality
       input_columns:
       - qty_sold
       - month
       output_columns:
       - month_season_coeffficient
       store_in_model: true
       stored_keys:
       - month
       - qty_sold
       stored_columns:
       - month_season_coeffficient
       params:
         time_col: month
         value: qty_sold
   ```

Example of output:

| month | month\_season\_coeffficient |
| ----- | --------------------------- |
| 1     | 0.95168072905404733         |
| 2     | 1.0357862750651963          |
| 3     | 1.0792659328597893          |
| 4     | 1.0395920562861072          |
| 5     | 1.0606537886934222          |
| 6     | 1.077858133811912           |
| 7     | 0.90191046323711832         |
| 8     | 0.95522180681369606         |
| 9     | 1.0252685243518904          |
| 10    | 0.97325249153619431         |
| 11    | 0.82898384742434672         |
| 12    | 0.99689396468790548         |

2. Imagine you have `model_resolution` in your model. In this case, your coefficient will be computed per resolution. If you want to maintain the computation as described above, use `global: true`.

   ```yaml
   preprocessing:  
     model_resolution:
     - country
     - pos_size
     
   calculated_cols:
     month_coefficient:
       method: seasonality
       input_columns:
       - qty_sold
       - month
       output_columns:
       - month_season_coeffficient
       store_in_model: true
       stored_keys:
       - month
       - qty_sold
       stored_columns:
       - month_season_coeffficient
       params:
         time_col: month
         value: qty_sold
   ```

Example of output:

<table><thead><tr><th>month</th><th width="243">month_season_coeffficient</th><th>country</th><th>pos_size</th></tr></thead><tbody><tr><td>1</td><td>0.56073028043659023</td><td>BELGIUM</td><td>JUMBO</td></tr><tr><td>2</td><td>0.7477214898040766</td><td>BELGIUM</td><td>JUMBO</td></tr><tr><td>1</td><td>0.97832471421812339</td><td>BELGIUM</td><td>MEDIUM</td></tr><tr><td>2</td><td>1.0817738908560632</td><td>BELGIUM</td><td>MEDIUM</td></tr><tr><td>1</td><td>0.8893741423322854</td><td>BELGIUM</td><td>XS</td></tr><tr><td>2</td><td>1.2777182380138707</td><td>BELGIUM</td><td>XS</td></tr><tr><td>1</td><td>0.94944234555496687</td><td>IRELAND</td><td>JUMBO</td></tr><tr><td>2</td><td>0.99525831058681336</td><td>IRELAND</td><td>JUMBO</td></tr><tr><td>1</td><td>0.927610409362476</td><td>IRELAND</td><td>LARGE</td></tr><tr><td>2</td><td>1.016215614376581</td><td>IRELAND</td><td>LARGE</td></tr><tr><td>1</td><td>0.89273852338090465</td><td>IRELAND</td><td>MEGA</td></tr><tr><td>2</td><td>1.0118941815702633</td><td>IRELAND</td><td>MEGA</td></tr><tr><td>1</td><td>0.9948854555639558</td><td>LUXEMBOURG</td><td>JUMBO</td></tr><tr><td>2</td><td>1.0520470613380593</td><td>LUXEMBOURG</td><td>JUMBO</td></tr><tr><td>1</td><td>0.93302404196451849</td><td>LUXEMBOURG</td><td>LARGE</td></tr><tr><td>2</td><td>0.95808824169437257</td><td>LUXEMBOURG</td><td>LARGE</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.verteego.com/verteego-doc/pipelines/forecasting-pipelines/calculators/temporal/seasonality.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
