sdk_reference.mdx 27.2 KB
Newer Older
bailuo's avatar
readme  
bailuo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
---
output-file: nixtla_client.html
title: SDK Reference
icon: 'code'
---


------------------------------------------------------------------------

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

## NixtlaClient

> ``` text
>  NixtlaClient (api_key:Optional[str]=None, base_url:Optional[str]=None,
>                timeout:Optional[int]=60, max_retries:int=6,
>                retry_interval:int=10, max_wait_time:int=360)
> ```

*Client to interact with the Nixtla API.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| api_key | Optional | None | The authorization api_key interacts with the Nixtla API.<br/>If not provided, will use the NIXTLA_API_KEY environment variable. |
| base_url | Optional | None | Custom base_url.<br/>If not provided, will use the NIXTLA_BASE_URL environment variable. |
| timeout | Optional | 60 | Request timeout in seconds. Set this to `None` to disable it. |
| max_retries | int | 6 | The maximum number of attempts to make when calling the API before giving up.<br/>It defines how many times the client will retry the API call if it fails.<br/>Default value is 6, indicating the client will attempt the API call up to 6 times in total |
| retry_interval | int | 10 | The interval in seconds between consecutive retry attempts.<br/>This is the waiting period before the client tries to call the API again after a failed attempt.<br/>Default value is 10 seconds, meaning the client waits for 10 seconds between retries. |
| max_wait_time | int | 360 | The maximum total time in seconds that the client will spend on all retry attempts before giving up.<br/>This sets an upper limit on the cumulative waiting time for all retry attempts.<br/>If this time is exceeded, the client will stop retrying and raise an exception.<br/>Default value is 360 seconds, meaning the client will cease retrying if the total time<br/>spent on retries exceeds 360 seconds.<br/>The client throws a ReadTimeout error after 60 seconds of inactivity. If you want to<br/>catch these errors, use max_wait_time \>\> 60. |

------------------------------------------------------------------------

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

## NixtlaClient.validate_api_key

> ``` text
>  NixtlaClient.validate_api_key (log:bool=True)
> ```

*Check API key status.*

|             | **Type** | **Default** | **Details**                   |
|-------------|----------|-------------|-------------------------------|
| log         | bool     | True        | Show the endpoint’s response. |
| **Returns** | **bool** |             | **Whether API key is valid.** |

------------------------------------------------------------------------

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

## NixtlaClient.forecast

> ``` text
>  NixtlaClient.forecast (df:~AnyDFType, h:typing.Annotated[int,Gt(gt=0)],
>                         freq:Union[str,int,pandas._libs.tslibs.offsets.Bas
>                         eOffset,NoneType]=None, id_col:str='unique_id',
>                         time_col:str='ds', target_col:str='y',
>                         X_df:Optional[~AnyDFType]=None,
>                         level:Optional[list[Union[int,float]]]=None,
>                         quantiles:Optional[list[float]]=None,
>                         finetune_steps:typing.Annotated[int,Ge(ge=0)]=0,
>                         finetune_depth:Literal[1,2,3,4,5]=1, finetune_loss
>                         :Literal['default','mae','mse','rmse','mape','smap
>                         e']='default',
>                         finetuned_model_id:Optional[str]=None,
>                         clean_ex_first:bool=True,
>                         hist_exog_list:Optional[list[str]]=None,
>                         validate_api_key:bool=False,
>                         add_history:bool=False, date_features:Union[bool,l
>                         ist[Union[str,Callable]]]=False, date_features_to_
>                         one_hot:Union[bool,list[str]]=False, model:Literal
>                         ['azureai','timegpt-1','timegpt-1-long-
>                         horizon']='timegpt-1', num_partitions:Optional[Ann
>                         otated[int,Gt(gt=0)]]=None,
>                         feature_contributions:bool=False)
> ```

*Forecast your time series using TimeGPT.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| df | AnyDFType |  | The DataFrame on which the function will operate. Expected to contain at least the following columns:<br/>- time_col:<br/> Column name in `df` that contains the time indices of the time series. This is typically a datetime<br/> column with regular intervals, e.g., hourly, daily, monthly data points.<br/>- target_col:<br/> Column name in `df` that contains the target variable of the time series, i.e., the variable we<br/> wish to predict or analyze.<br/>Additionally, you can pass multiple time series (stacked in the dataframe) considering an additional column:<br/>- id_col:<br/> Column name in `df` that identifies unique time series. Each unique value in this column<br/> corresponds to a unique time series. |
| h | Annotated |  | Forecast horizon. |
| freq | Union | None | Frequency of the timestamps. If `None`, it will be inferred automatically.<br/>See [pandas’ available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases). |
| id_col | str | unique_id | Column that identifies each series. |
| time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
| target_col | str | y | Column that contains the target. |
| X_df | Optional | None | DataFrame with \[`unique_id`, `ds`\] columns and `df`’s future exogenous. |
| level | Optional | None | Confidence levels between 0 and 100 for prediction intervals. |
| quantiles | Optional | None | Quantiles to forecast, list between (0, 1).<br/>`level` and `quantiles` should not be used simultaneously.<br/>The output dataframe will have the quantile columns<br/>formatted as TimeGPT-q-(100 \* q) for each q.<br/>100 \* q represents percentiles but we choose this notation<br/>to avoid having dots in column names. |
| finetune_steps | Annotated | 0 | Number of steps used to finetune learning TimeGPT in the<br/>new data. |
| finetune_depth | Literal | 1 | The depth of the finetuning. Uses a scale from 1 to 5, where 1 means little finetuning,<br/>and 5 means that the entire model is finetuned. |
| finetune_loss | Literal | default | Loss function to use for finetuning. Options are: `default`, `mae`, `mse`, `rmse`, `mape`, and `smape`. |
| finetuned_model_id | Optional | None | ID of previously fine-tuned model to use. |
| clean_ex_first | bool | True | Clean exogenous signal before making forecasts using TimeGPT. |
| hist_exog_list | Optional | None | Column names of the historical exogenous features. |
| validate_api_key | bool | False | If True, validates api_key before sending requests. |
| add_history | bool | False | Return fitted values of the model. |
| date_features | Union | False | Features computed from the dates.<br/>Can be pandas date attributes or functions that will take the dates as input.<br/>If True automatically adds most used date features for the<br/>frequency of `df`. |
| date_features_to_one_hot | Union | False | Apply one-hot encoding to these date features.<br/>If `date_features=True`, then all date features are<br/>one-hot encoded by default. |
| model | Literal | timegpt-1 | Model to use as a string. Options are: `timegpt-1`, and `timegpt-1-long-horizon`.<br/>We recommend using `timegpt-1-long-horizon` for forecasting<br/>if you want to predict more than one seasonal<br/>period given the frequency of your data. |
| num_partitions | Optional | None | Number of partitions to use.<br/>If None, the number of partitions will be equal<br/>to the available parallel resources in distributed environments. |
| feature_contributions | bool | False |  |
| **Returns** | **AnyDFType** |  | **DataFrame with TimeGPT forecasts for point predictions and probabilistic<br/>predictions (if level is not None).** |

------------------------------------------------------------------------

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

## NixtlaClient.cross_validation

> ``` text
>  NixtlaClient.cross_validation (df:~AnyDFType,
>                                 h:typing.Annotated[int,Gt(gt=0)], freq:Uni
>                                 on[str,int,pandas._libs.tslibs.offsets.Bas
>                                 eOffset,NoneType]=None,
>                                 id_col:str='unique_id', time_col:str='ds',
>                                 target_col:str='y', level:Optional[list[Un
>                                 ion[int,float]]]=None,
>                                 quantiles:Optional[list[float]]=None,
>                                 validate_api_key:bool=False, n_windows:typ
>                                 ing.Annotated[int,Gt(gt=0)]=1, step_size:O
>                                 ptional[Annotated[int,Gt(gt=0)]]=None, fin
>                                 etune_steps:typing.Annotated[int,Ge(ge=0)]
>                                 =0, finetune_depth:Literal[1,2,3,4,5]=1, f
>                                 inetune_loss:Literal['default','mae','mse'
>                                 ,'rmse','mape','smape']='default',
>                                 finetuned_model_id:Optional[str]=None,
>                                 refit:bool=True, clean_ex_first:bool=True,
>                                 hist_exog_list:Optional[list[str]]=None,
>                                 date_features:Union[bool,list[str]]=False,
>                                 date_features_to_one_hot:Union[bool,list[s
>                                 tr]]=False, model:Literal['azureai','timeg
>                                 pt-1','timegpt-1-long-
>                                 horizon']='timegpt-1', num_partitions:Opti
>                                 onal[Annotated[int,Gt(gt=0)]]=None)
> ```

*Perform cross validation in your time series using TimeGPT.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| df | AnyDFType |  | The DataFrame on which the function will operate. Expected to contain at least the following columns:<br/>- time_col:<br/> Column name in `df` that contains the time indices of the time series. This is typically a datetime<br/> column with regular intervals, e.g., hourly, daily, monthly data points.<br/>- target_col:<br/> Column name in `df` that contains the target variable of the time series, i.e., the variable we<br/> wish to predict or analyze.<br/>Additionally, you can pass multiple time series (stacked in the dataframe) considering an additional column:<br/>- id_col:<br/> Column name in `df` that identifies unique time series. Each unique value in this column<br/> corresponds to a unique time series. |
| h | Annotated |  | Forecast horizon. |
| freq | Union | None | Frequency of the timestamps. If `None`, it will be inferred automatically.<br/>See [pandas’ available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases). |
| id_col | str | unique_id | Column that identifies each series. |
| time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
| target_col | str | y | Column that contains the target. |
| level | Optional | None | Confidence level between 0 and 100 for prediction intervals. |
| quantiles | Optional | None | Quantiles to forecast, list between (0, 1).<br/>`level` and `quantiles` should not be used simultaneously.<br/>The output dataframe will have the quantile columns<br/>formatted as TimeGPT-q-(100 \* q) for each q.<br/>100 \* q represents percentiles but we choose this notation<br/>to avoid having dots in column names. |
| validate_api_key | bool | False | If True, validates api_key before sending requests. |
| n_windows | Annotated | 1 | Number of windows to evaluate. |
| step_size | Optional | None | Step size between each cross validation window. If None it will be equal to `h`. |
| finetune_steps | Annotated | 0 | Number of steps used to finetune TimeGPT in the<br/>new data. |
| finetune_depth | Literal | 1 | The depth of the finetuning. Uses a scale from 1 to 5, where 1 means little finetuning,<br/>and 5 means that the entire model is finetuned. |
| finetune_loss | Literal | default | Loss function to use for finetuning. Options are: `default`, `mae`, `mse`, `rmse`, `mape`, and `smape`. |
| finetuned_model_id | Optional | None | ID of previously fine-tuned model to use. |
| refit | bool | True | Fine-tune the model in each window. If `False`, only fine-tunes on the first window.<br/>Only used if `finetune_steps` \> 0. |
| clean_ex_first | bool | True | Clean exogenous signal before making forecasts using TimeGPT. |
| hist_exog_list | Optional | None | Column names of the historical exogenous features. |
| date_features | Union | False | Features computed from the dates.<br/>Can be pandas date attributes or functions that will take the dates as input.<br/>If True automatically adds most used date features for the<br/>frequency of `df`. |
| date_features_to_one_hot | Union | False | Apply one-hot encoding to these date features.<br/>If `date_features=True`, then all date features are<br/>one-hot encoded by default. |
| model | Literal | timegpt-1 | Model to use as a string. Options are: `timegpt-1`, and `timegpt-1-long-horizon`.<br/>We recommend using `timegpt-1-long-horizon` for forecasting<br/>if you want to predict more than one seasonal<br/>period given the frequency of your data. |
| num_partitions | Optional | None | Number of partitions to use.<br/>If None, the number of partitions will be equal<br/>to the available parallel resources in distributed environments. |
| **Returns** | **AnyDFType** |  | **DataFrame with cross validation forecasts.** |

------------------------------------------------------------------------

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

## NixtlaClient.detect_anomalies

> ``` text
>  NixtlaClient.detect_anomalies (df:~AnyDFType,
>                                 freq:Union[str,int,pandas._libs.tslibs.off
>                                 sets.BaseOffset,NoneType]=None,
>                                 id_col:str='unique_id', time_col:str='ds',
>                                 target_col:str='y',
>                                 level:Union[int,float]=99,
>                                 finetuned_model_id:Optional[str]=None,
>                                 clean_ex_first:bool=True,
>                                 validate_api_key:bool=False,
>                                 date_features:Union[bool,list[str]]=False,
>                                 date_features_to_one_hot:Union[bool,list[s
>                                 tr]]=False, model:Literal['azureai','timeg
>                                 pt-1','timegpt-1-long-
>                                 horizon']='timegpt-1', num_partitions:Opti
>                                 onal[Annotated[int,Gt(gt=0)]]=None)
> ```

*Detect anomalies in your time series using TimeGPT.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| df | AnyDFType |  | The DataFrame on which the function will operate. Expected to contain at least the following columns:<br/>- time_col:<br/> Column name in `df` that contains the time indices of the time series. This is typically a datetime<br/> column with regular intervals, e.g., hourly, daily, monthly data points.<br/>- target_col:<br/> Column name in `df` that contains the target variable of the time series, i.e., the variable we<br/> wish to predict or analyze.<br/>Additionally, you can pass multiple time series (stacked in the dataframe) considering an additional column:<br/>- id_col:<br/> Column name in `df` that identifies unique time series. Each unique value in this column<br/> corresponds to a unique time series. |
| freq | Union | None | Frequency of the timestamps. If `None`, it will be inferred automatically.<br/>See [pandas’ available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases). |
| id_col | str | unique_id | Column that identifies each series. |
| time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
| target_col | str | y | Column that contains the target. |
| level | Union | 99 | Confidence level between 0 and 100 for detecting the anomalies. |
| finetuned_model_id | Optional | None | ID of previously fine-tuned model to use. |
| clean_ex_first | bool | True | Clean exogenous signal before making forecasts<br/>using TimeGPT. |
| validate_api_key | bool | False | If True, validates api_key before sending requests. |
| date_features | Union | False | Features computed from the dates.<br/>Can be pandas date attributes or functions that will take the dates as input.<br/>If True automatically adds most used date features for the<br/>frequency of `df`. |
| date_features_to_one_hot | Union | False | Apply one-hot encoding to these date features.<br/>If `date_features=True`, then all date features are<br/>one-hot encoded by default. |
| model | Literal | timegpt-1 | Model to use as a string. Options are: `timegpt-1`, and `timegpt-1-long-horizon`.<br/>We recommend using `timegpt-1-long-horizon` for forecasting<br/>if you want to predict more than one seasonal<br/>period given the frequency of your data. |
| num_partitions | Optional | None | Number of partitions to use.<br/>If None, the number of partitions will be equal<br/>to the available parallel resources in distributed environments. |
| **Returns** | **AnyDFType** |  | **DataFrame with anomalies flagged by TimeGPT.** |

------------------------------------------------------------------------

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

## NixtlaClient.usage

> ``` text
>  NixtlaClient.usage ()
> ```

*Query consumed requests and limits*

------------------------------------------------------------------------

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

## NixtlaClient.finetune

> ``` text
>  NixtlaClient.finetune
>                         (df:Union[pandas.core.frame.DataFrame,polars.dataf
>                         rame.frame.DataFrame], freq:Union[str,int,pandas._
>                         libs.tslibs.offsets.BaseOffset,NoneType]=None,
>                         id_col:str='unique_id', time_col:str='ds',
>                         target_col:str='y',
>                         finetune_steps:typing.Annotated[int,Ge(ge=0)]=10,
>                         finetune_depth:Literal[1,2,3,4,5]=1, finetune_loss
>                         :Literal['default','mae','mse','rmse','mape','smap
>                         e']='default', output_model_id:Optional[str]=None,
>                         finetuned_model_id:Optional[str]=None, model:Liter
>                         al['azureai','timegpt-1','timegpt-1-long-
>                         horizon']='timegpt-1')
> ```

*Fine-tune TimeGPT to your series.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| df | Union |  | The DataFrame on which the function will operate. Expected to contain at least the following columns:<br/>- time_col:<br/> Column name in `df` that contains the time indices of the time series. This is typically a datetime<br/> column with regular intervals, e.g., hourly, daily, monthly data points.<br/>- target_col:<br/> Column name in `df` that contains the target variable of the time series, i.e., the variable we<br/> wish to predict or analyze.<br/>Additionally, you can pass multiple time series (stacked in the dataframe) considering an additional column:<br/>- id_col:<br/> Column name in `df` that identifies unique time series. Each unique value in this column<br/> corresponds to a unique time series. |
| freq | Union | None | Frequency of the timestamps. If `None`, it will be inferred automatically.<br/>See [pandas’ available frequencies](https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#offset-aliases). |
| id_col | str | unique_id | Column that identifies each series. |
| time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
| target_col | str | y | Column that contains the target. |
| finetune_steps | Annotated | 10 | Number of steps used to finetune learning TimeGPT in the new data. |
| finetune_depth | Literal | 1 | The depth of the finetuning. Uses a scale from 1 to 5, where 1 means little finetuning,<br/>and 5 means that the entire model is finetuned. |
| finetune_loss | Literal | default | Loss function to use for finetuning. Options are: `default`, `mae`, `mse`, `rmse`, `mape`, and `smape`. |
| output_model_id | Optional | None | ID to assign to the fine-tuned model. If `None`, an UUID is used. |
| finetuned_model_id | Optional | None | ID of previously fine-tuned model to use as base. |
| model | Literal | timegpt-1 | Model to use as a string. Options are: `timegpt-1`, and `timegpt-1-long-horizon`.<br/>We recommend using `timegpt-1-long-horizon` for forecasting<br/>if you want to predict more than one seasonal<br/>period given the frequency of your data. |
| **Returns** | **str** |  | **ID of the fine-tuned model** |

------------------------------------------------------------------------

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

## NixtlaClient.finetuned_models

> ``` text
>  NixtlaClient.finetuned_models (as_df:bool=False)
> ```

*List fine-tuned models*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| as_df | bool | False | Return the fine-tuned models as a pandas dataframe |
| **Returns** | **Union** |  | **List of available fine-tuned models.** |

------------------------------------------------------------------------

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

## NixtlaClient.finetuned_model

> ``` text
>  NixtlaClient.finetuned_model (finetuned_model_id:str)
> ```

*Get fine-tuned model metadata*

|  | **Type** | **Details** |
|--------|---------------------------|-------------------------------------|
| finetuned_model_id | str | ID of the fine-tuned model to get metadata from. |
| **Returns** | **FinetunedModel** | **Fine-tuned model metadata.** |

------------------------------------------------------------------------

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

## NixtlaClient.delete_finetuned_model

> ``` text
>  NixtlaClient.delete_finetuned_model (finetuned_model_id:str)
> ```

*Delete a previously fine-tuned model*

|                    | **Type** | **Details**                               |
|--------------------|----------|-------------------------------------------|
| finetuned_model_id | str      | ID of the fine-tuned model to be deleted. |
| **Returns**        | **bool** | **Whether delete was successful.**        |

------------------------------------------------------------------------

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

## NixtlaClient.plot

> ``` text
>  NixtlaClient.plot (df:Union[pandas.core.frame.DataFrame,polars.dataframe.
>                     frame.DataFrame,NoneType]=None, forecasts_df:Union[pan
>                     das.core.frame.DataFrame,polars.dataframe.frame.DataFr
>                     ame,NoneType]=None, id_col:str='unique_id',
>                     time_col:str='ds', target_col:str='y', unique_ids:Unio
>                     n[list[str],NoneType,numpy.ndarray]=None,
>                     plot_random:bool=True, max_ids:int=8,
>                     models:Optional[list[str]]=None,
>                     level:Optional[list[Union[int,float]]]=None,
>                     max_insample_length:Optional[int]=None,
>                     plot_anomalies:bool=False,
>                     engine:Literal['matplotlib','plotly','plotly-
>                     resampler']='matplotlib',
>                     resampler_kwargs:Optional[dict]=None, ax:Union[Forward
>                     Ref('plt.Axes'),numpy.ndarray,ForwardRef('plotly.graph
>                     _objects.Figure'),NoneType]=None)
> ```

*Plot forecasts and insample values.*

|  | **Type** | **Default** | **Details** |
|------|------------------|-------------------------|-------------------------|
| df | Union | None | The DataFrame on which the function will operate. Expected to contain at least the following columns:<br/>- time_col:<br/> Column name in `df` that contains the time indices of the time series. This is typically a datetime<br/> column with regular intervals, e.g., hourly, daily, monthly data points.<br/>- target_col:<br/> Column name in `df` that contains the target variable of the time series, i.e., the variable we<br/> wish to predict or analyze.<br/>Additionally, you can pass multiple time series (stacked in the dataframe) considering an additional column:<br/>- id_col:<br/> Column name in `df` that identifies unique time series. Each unique value in this column<br/> corresponds to a unique time series. |
| forecasts_df | Union | None | DataFrame with columns \[`unique_id`, `ds`\] and models. |
| id_col | str | unique_id | Column that identifies each series. |
| time_col | str | ds | Column that identifies each timestep, its values can be timestamps or integers. |
| target_col | str | y | Column that contains the target. |
| unique_ids | Union | None | Time Series to plot.<br/>If None, time series are selected randomly. |
| plot_random | bool | True | Select time series to plot randomly. |
| max_ids | int | 8 | Maximum number of ids to plot. |
| models | Optional | None | list of models to plot. |
| level | Optional | None | list of prediction intervals to plot if paseed. |
| max_insample_length | Optional | None | Max number of train/insample observations to be plotted. |
| plot_anomalies | bool | False | Plot anomalies for each prediction interval. |
| engine | Literal | matplotlib | Library used to plot. ‘matplotlib’, ‘plotly’ or ‘plotly-resampler’. |
| resampler_kwargs | Optional | None | Kwargs to be passed to plotly-resampler constructor.<br/>For further custumization (“show_dash”) call the method,<br/>store the plotting object and add the extra arguments to<br/>its `show_dash` method. |
| ax | Union | None | Object where plots will be added. |