Loading...

vastorbit.machine_learning.model_selection.hp_tuning.plot_acf_pacf

vastorbit.machine_learning.model_selection.hp_tuning.plot_acf_pacf(vdf: VastFrame, column: str, ts: str, by: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, p: int | list = 15, show: bool = True, **style_kwargs) TableSample

Draws the ACF and PACF Charts.

Parameters:
  • vdf (VastFrame) – Input VastFrame.

  • column (str) – Response column.

  • ts (str) – VastColumn used as timeline to order the data. It can be a numerical or date-like type (date, datetime, timestamp…) VastColumn.

  • by (list, optional) – VastColumns used in the partition.

  • p (int | list, optional) – Integer equal to the maximum number of lags to consider during the computation or a list of the different lags to include during the computation. p must be positive or a list of positive integers.

  • show (bool, optional) – If set to True, the Plotting object is returned.

  • **style_kwargs – Any optional parameter to pass to the Plotting functions.

Returns:

acf, pacf, confidence

Return type:

TableSample

Examples

We import vastorbit:

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

For this example, we will use the amazon dataset.

import vastorbit.datasets as vod

amazon = vod.load_amazon()
📅
date
Date
Abc
state
Varchar(32)
123
number
Integer
12016-01-01PARAÍBA18
22016-02-01PARAÍBA4
32016-03-01PARAÍBA1
42016-04-01PARAÍBA1
52016-05-01PARAÍBA1
62016-06-01PARAÍBA4
72016-07-01PARAÍBA22
82016-08-01PARAÍBA50
92016-09-01PARAÍBA131
102016-10-01PARAÍBA304
112016-11-01PARAÍBA132
122016-12-01PARAÍBA8
132016-01-01PARÁ1322
142016-02-01PARÁ430
152016-03-01PARÁ81
162016-04-01PARÁ66
172016-05-01PARÁ154
182016-06-01PARÁ502
192016-07-01PARÁ1579
202016-08-01PARÁ4863
212016-09-01PARÁ3953
222016-10-01PARÁ5281
232016-11-01PARÁ7879
242016-12-01PARÁ3300
252016-01-01PERNAMBUCO24
262016-02-01PERNAMBUCO19
272016-03-01PERNAMBUCO4
282016-04-01PERNAMBUCO8
292016-05-01PERNAMBUCO6
302016-06-01PERNAMBUCO4
312016-07-01PERNAMBUCO17
322016-08-01PERNAMBUCO42
332016-09-01PERNAMBUCO171
342016-10-01PERNAMBUCO319
352016-11-01PERNAMBUCO191
362016-12-01PERNAMBUCO161
372016-01-01PIAUÍ94
382016-02-01PIAUÍ97
392016-03-01PIAUÍ53
402016-04-01PIAUÍ35
412016-05-01PIAUÍ60
422016-06-01PIAUÍ153
432016-07-01PIAUÍ754
442016-08-01PIAUÍ1647
452016-09-01PIAUÍ1394
462016-10-01PIAUÍ2598
472016-11-01PIAUÍ1126
482016-12-01PIAUÍ374
492016-01-01RIO DE JANEIRO9
502016-02-01RIO DE JANEIRO16
512016-03-01RIO DE JANEIRO16
522016-04-01RIO DE JANEIRO45
532016-05-01RIO DE JANEIRO30
542016-06-01RIO DE JANEIRO37
552016-07-01RIO DE JANEIRO131
562016-08-01RIO DE JANEIRO241
572016-09-01RIO DE JANEIRO195
582016-10-01RIO DE JANEIRO30
592016-11-01RIO DE JANEIRO19
602016-12-01RIO DE JANEIRO5
612016-01-01RIO GRANDE DO NORTE15
622016-02-01RIO GRANDE DO NORTE2
632016-03-01RIO GRANDE DO NORTE1
642016-04-01RIO GRANDE DO NORTE0
652016-05-01RIO GRANDE DO NORTE1
662016-06-01RIO GRANDE DO NORTE4
672016-07-01RIO GRANDE DO NORTE13
682016-08-01RIO GRANDE DO NORTE24
692016-09-01RIO GRANDE DO NORTE44
702016-10-01RIO GRANDE DO NORTE129
712016-11-01RIO GRANDE DO NORTE93
722016-12-01RIO GRANDE DO NORTE75
732016-01-01RIO GRANDE DO SUL68
742016-02-01RIO GRANDE DO SUL55
752016-03-01RIO GRANDE DO SUL30
762016-04-01RIO GRANDE DO SUL32
772016-05-01RIO GRANDE DO SUL37
782016-06-01RIO GRANDE DO SUL261
792016-07-01RIO GRANDE DO SUL865
802016-08-01RIO GRANDE DO SUL1111
812016-09-01RIO GRANDE DO SUL628
822016-10-01RIO GRANDE DO SUL93
832016-11-01RIO GRANDE DO SUL105
842016-12-01RIO GRANDE DO SUL79
852016-01-01RONDÔNIA93
862016-02-01RONDÔNIA88
872016-03-01RONDÔNIA25
882016-04-01RONDÔNIA59
892016-05-01RONDÔNIA44
902016-06-01RONDÔNIA170
912016-07-01RONDÔNIA969
922016-08-01RONDÔNIA3675
932016-09-01RONDÔNIA4208
942016-10-01RONDÔNIA1844
952016-11-01RONDÔNIA401
962016-12-01RONDÔNIA148
972016-01-01RORAIMA1754
982016-02-01RORAIMA171
992016-03-01RORAIMA1081
1002016-04-01RORAIMA126
Rows: 1-100 | Columns: 3

Note

vastorbit offers a wide range of sample datasets that are ideal for training and testing purposes. You can explore the full list of available datasets in the Datasets, which provides detailed information on each dataset and how to use them effectively. These datasets are invaluable resources for honing your data analysis and machine learning skills within the vastorbit environment.

Let’s select only one state to get a refined plot.

amazon = amazon[amazon["state"] == "ACRE"]

We can have a look at the time-series plot using the VastFrame.plot():

amazon["number"].plot(ts = "date")

Now we can plot the ACF and PACF plots together:

from vastorbit.machine_learning.model_selection import plot_acf_pacf

plot_acf_pacf(
    amazon,
    column = "number",
    ts = "date",
    p = 40,
)
acfpacfconfidence
01.01.00.1267795309147783
10.49567930.49567930.15515153986757108
2-0.009024917-0.341521620.1671963987248046
3-0.13944740.0485607760.16777918973880393
4-0.15902446-0.139652130.17002132416812135
5-0.16210829-0.064407620.17078345455817712
6-0.1638135-0.1124560460.17236347752969797
7-0.16318145-0.103581860.17375998863807843
8-0.16027784-0.124072070.17559962464166412
9-0.14143026-0.111573170.17715847810361873
10-0.0270293580.0157735090.17756837174087073
110.362489460.42479690.19429236850351983
120.76169210.57872530.22192665765986883
130.3767513-0.37120050.23270917856856066
14-0.0338309850.173762840.2354256601429028
15-0.14322689-0.127816570.2371350177977126
16-0.160050290.032140640.23774097849119158
17-0.16268563-0.05193630.23847163588598974
18-0.16413334-0.0101225640477514020.23901800732330247
19-0.16434976-0.0358384620.23965421333321657
20-0.16219983-0.0254987550.24024822173657268
21-0.14461099-0.0338210650.24088231146275282
22-0.0263706130.0254502560.24148418886869322
230.396798970.371855770.2519979398680095
240.780928130.219777350.2559772942029684
250.36100402-0.1719470.2586349142576604
26-0.05738610.056230830.25946120323013666
27-0.15295441-0.043727870.2602056100597141
28-0.16122450.0099356010.2608283727222244
29-0.16341664-0.0206618980.2614785230996206
30-0.16503948-0.0048557620.2621049767776744
31-0.16516642-0.0162162330.2627527655543581
32-0.16308495-0.00454976740.2633881279176183
33-0.14744943-0.0306282380.26409289321972557
34-0.05059044-0.041697930.26485928164119005
350.29349113-0.073827814271478960.2658939426901845
360.647929670.086330880.26707664858197155
370.29542336-0.0796787960.2681874775795322
38-0.0607319660.07412580.2692440910587496
39-0.15466514-0.095415160.2705634323233808
40-0.163256350.0508038250.27142601287474954
Rows: 1-41 | Columns: 4

See also

acf() : ACF plot from a VastFrame.
pacf() : PACF plot from a VastFrame.