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

> The `core.NeuralForecast` class allows you to efficiently fit multiple `NeuralForecast` models for large sets of time series. It operates with pandas DataFrame `df` that identifies individual series and datestamps with the `unique_id` and `ds` columns, and the `y` column denotes the target time series variable. To assist development, we declare useful datasets that we use throughout all `NeuralForecast`'s unit tests.<br/><br/>

# Example Data

# 1. Synthetic Panel Data

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L21" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### generate\_series

> ```text theme={null}
>  generate_series (n_series:int, freq:str='D', min_length:int=50,
>                   max_length:int=500, n_temporal_features:int=0,
>                   n_static_features:int=0, equal_ends:bool=False,
>                   seed:int=0)
> ```

\*Generate Synthetic Panel Series.

Generates `n_series` of frequency `freq` of different lengths in the
interval \[`min_length`, `max_length`]. If `n_temporal_features > 0`,
then each serie gets temporal features with random values. If
`n_static_features > 0`, then a static dataframe is returned along the
temporal dataframe. If `equal_ends == True` then all series end at the
same date.

**Parameters:**<br /> `n_series`: int, number of series for synthetic
panel.<br /> `min_length`: int, minimal length of synthetic panel’s
series.<br /> `max_length`: int, minimal length of synthetic panel’s
series.<br /> `n_temporal_features`: int, default=0, number of temporal
exogenous variables for synthetic panel’s series.<br />
`n_static_features`: int, default=0, number of static exogenous
variables for synthetic panel’s series.<br /> `equal_ends`: bool, if True,
series finish in the same date stamp `ds`.<br /> `freq`: str, frequency of
the data, [panda’s available
frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases).<br />

**Returns:**<br /> `freq`: pandas.DataFrame, synthetic panel with columns
\[`unique_id`, `ds`, `y`] and exogenous.\*

```python theme={null}
synthetic_panel = generate_series(n_series=2)
synthetic_panel.groupby('unique_id').head(4)
```

```python theme={null}
temporal_df, static_df = generate_series(n_series=1000, n_static_features=2,
                                         n_temporal_features=4, equal_ends=False)
static_df.head(2)
```

# 2. AirPassengers Data

The classic Box & Jenkins airline data. Monthly totals of international
airline passengers, 1949 to 1960.

It has been used as a reference on several forecasting libraries, since
it is a series that shows clear trends and seasonalities it offers a
nice opportunity to quickly showcase a model’s predictions performance.

```python theme={null}
AirPassengersDF.head(12)
```

```python theme={null}
#We are going to plot the ARIMA predictions, and the prediction intervals.
fig, ax = plt.subplots(1, 1, figsize = (20, 7))
plot_df = AirPassengersDF.set_index('ds')

plot_df[['y']].plot(ax=ax, linewidth=2)
ax.set_title('AirPassengers Forecast', fontsize=22)
ax.set_ylabel('Monthly Passengers', fontsize=20)
ax.set_xlabel('Timestamp [t]', fontsize=20)
ax.legend(prop={'size': 15})
ax.grid()
```

```python theme={null}
import numpy as np
import pandas as pd
```

```python theme={null}
n_static_features = 3
n_series = 5

static_features = np.random.uniform(low=0.0, high=1.0, 
                        size=(n_series, n_static_features))
static_df = pd.DataFrame.from_records(static_features, 
                   columns = [f'static_{i}'for i in  range(n_static_features)])
static_df['unique_id'] = np.arange(n_series)
```

```python theme={null}
static_df
```

# 3. Panel AirPassengers Data

Extension to classic Box & Jenkins airline data. Monthly totals of
international airline passengers, 1949 to 1960.

It includes two series with static, temporal and future exogenous
variables, that can help to explore the performance of models like
[`NBEATSx`](https://nixtlaverse.nixtla.io/neuralforecast/models.nbeatsx.html#nbeatsx)
and
[`TFT`](https://nixtlaverse.nixtla.io/neuralforecast/models.tft.html#tft).

```python theme={null}
fig, ax = plt.subplots(1, 1, figsize = (20, 7))
plot_df = AirPassengersPanel.set_index('ds')

plot_df.groupby('unique_id')['y'].plot(legend=True)
ax.set_title('AirPassengers Panel Data', fontsize=22)
ax.set_ylabel('Monthly Passengers', fontsize=20)
ax.set_xlabel('Timestamp [t]', fontsize=20)
ax.legend(title='unique_id', prop={'size': 15})
ax.grid()
```

```python theme={null}
fig, ax = plt.subplots(1, 1, figsize = (20, 7))
plot_df = AirPassengersPanel[AirPassengersPanel.unique_id=='Airline1'].set_index('ds')

plot_df[['y', 'trend', 'y_[lag12]']].plot(ax=ax, linewidth=2)
ax.set_title('Box-Cox AirPassengers Data', fontsize=22)
ax.set_ylabel('Monthly Passengers', fontsize=20)
ax.set_xlabel('Timestamp [t]', fontsize=20)
ax.legend(prop={'size': 15})
ax.grid()
```

# 4. Time Features

We have developed a utility that generates normalized calendar features
for use as absolute positional embeddings in Transformer-based models.
These embeddings capture seasonal patterns in time series data and can
be easily incorporated into the model architecture. Additionally, the
features can be used as exogenous variables in other models to inform
them of calendar patterns in the data.

**References**<br /> - [Haoyi Zhou, Shanghang Zhang, Jieqi Peng, Shuai
Zhang, Jianxin Li, Hui Xiong, Wancai Zhang. “Informer: Beyond Efficient
Transformer for Long Sequence Time-Series
Forecasting”](https://arxiv.org/abs/2012.07436)<br />

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L404" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### augment\_calendar\_df

> ```text theme={null}
>  augment_calendar_df (df, freq='H')
> ```

\*> \* Q - \[month] > \* M - \[month] > \* W - \[Day of month, week
of year] > \* D - \[Day of week, day of month, day of year] > \* B -
\[Day of week, day of month, day of year] > \* H - \[Hour of day, day
of week, day of month, day of year] > \* T - \[Minute of hour\*, hour
of day, day of week, day of month, day of year] > \* S - \[Second of
minute, minute of hour, hour of day, day of week, day of month, day of
year] *minute returns a number from 0-3 corresponding to the 15 minute
period it falls into.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L366" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### time\_features\_from\_frequency\_str

> ```text theme={null}
>  time_features_from_frequency_str (freq_str:str)
> ```

*Returns a list of time features that will be appropriate for the given
frequency string. Parameters ———- freq\_str Frequency string of the form
\[multiple]\[granularity] such as “12H”, “5min”, “1D” etc.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L359" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### WeekOfYear

> ```text theme={null}
>  WeekOfYear ()
> ```

*Week of year encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L352" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### MonthOfYear

> ```text theme={null}
>  MonthOfYear ()
> ```

*Month of year encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L345" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### DayOfYear

> ```text theme={null}
>  DayOfYear ()
> ```

*Day of year encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L338" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### DayOfMonth

> ```text theme={null}
>  DayOfMonth ()
> ```

*Day of month encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L331" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### DayOfWeek

> ```text theme={null}
>  DayOfWeek ()
> ```

*Hour of day encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L324" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### HourOfDay

> ```text theme={null}
>  HourOfDay ()
> ```

*Hour of day encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L317" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### MinuteOfHour

> ```text theme={null}
>  MinuteOfHour ()
> ```

*Minute of hour encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L310" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### SecondOfMinute

> ```text theme={null}
>  SecondOfMinute ()
> ```

*Minute of hour encoded as value between \[-0.5, 0.5]*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L299" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### TimeFeature

> ```text theme={null}
>  TimeFeature ()
> ```

*Initialize self. See help(type(self)) for accurate signature.*

```python theme={null}
AirPassengerPanelCalendar, calendar_cols = augment_calendar_df(df=AirPassengersPanel, freq='M')
AirPassengerPanelCalendar.head()
```

```python theme={null}
plot_df = AirPassengerPanelCalendar[AirPassengerPanelCalendar.unique_id=='Airline1'].set_index('ds')
plt.plot(plot_df['month'])
plt.grid()
plt.xlabel('Datestamp')
plt.ylabel('Normalized Month')
plt.show()
```

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L446" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### get\_indexer\_raise\_missing

> ```text theme={null}
>  get_indexer_raise_missing (idx:pandas.core.indexes.base.Index,
>                             vals:List[str])
> ```

# 5. Prediction Intervals

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L454" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### PredictionIntervals

> ```text theme={null}
>  PredictionIntervals (n_windows:int=2,
>                       method:str='conformal_distribution')
> ```

*Class for storing prediction intervals metadata information.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L485" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### add\_conformal\_distribution\_intervals

> ```text theme={null}
>  add_conformal_distribution_intervals (model_fcsts:<built-
>                                        infunctionarray>, cs_df:~DFType,
>                                        model:str, cs_n_windows:int,
>                                        n_series:int, horizon:int, level:Op
>                                        tional[List[Union[int,float]]]=None
>                                        , quantiles:Optional[List[float]]=N
>                                        one)
> ```

*Adds conformal intervals to a `fcst_df` based on conformal scores
`cs_df`. `level` should be already sorted. This strategy creates
forecasts paths based on errors and calculate quantiles using those
paths.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L535" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### add\_conformal\_error\_intervals

> ```text theme={null}
>  add_conformal_error_intervals (model_fcsts:<built-infunctionarray>,
>                                 cs_df:~DFType, model:str,
>                                 cs_n_windows:int, n_series:int,
>                                 horizon:int, level:Optional[List[Union[int
>                                 ,float]]]=None,
>                                 quantiles:Optional[List[float]]=None)
> ```

*Adds conformal intervals to a `fcst_df` based on conformal scores
`cs_df`. `level` should be already sorted. This startegy creates
prediction intervals based on the absolute errors.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L595" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### get\_prediction\_interval\_method

> ```text theme={null}
>  get_prediction_interval_method (method:str)
> ```

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L620" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### quantiles\_to\_level

> ```text theme={null}
>  quantiles_to_level (quantiles:List[float])
> ```

*Converts a list of quantiles to a list of levels.*

***

<a href="https://github.com/Nixtla/neuralforecast/blob/main/neuralforecast/utils.py#L608" target="_blank" style={{ float: "right", fontSize: "smaller" }}>source</a>

### level\_to\_quantiles

> ```text theme={null}
>  level_to_quantiles (level:List[Union[int,float]])
> ```

*Converts a list of levels to a list of quantiles.*
