Loading...

verticapy.machine_learning.model_selection.hp_tuning.plot_acf_pacf

verticapy.machine_learning.model_selection.hp_tuning.plot_acf_pacf(vdf: vDataFrame, 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: vDataFrame

Input vDataFrame.

column: str

Response column.

ts: str

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

by: list, optional

vDataColumns 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

TableSample

acf, pacf, confidence

Examples

We import verticapy:

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy 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 verticapy are used as intended without interfering with functions from other libraries.

For this example, we will use the amazon dataset.

import verticapy.datasets as vpd

amazon = vpd.load_amazon()
📅
date
Date
Abc
state
Varchar(32)
123
number
Integer
11998-01-01AMAPÁ0
21998-01-01AMAZONAS0
31998-01-01DISTRITO FEDERAL0
41998-01-01ESPÍRITO SANTO0
51998-01-01MARANHÃO0
61998-01-01PARANÁ0
71998-01-01PIAUÍ0
81998-01-01RORAIMA0
91998-01-01SERGIPE0
101998-01-01SÃO PAULO0
111998-02-01GOIÁS0
121998-02-01MATO GROSSO DO SUL0
131998-02-01MINAS GERAIS0
141998-02-01PARAÍBA0
151998-02-01SANTA CATARINA0
161998-02-01SÃO PAULO0
171998-03-01AMAPÁ0
181998-03-01BAHIA0
191998-03-01MATO GROSSO DO SUL0
201998-03-01PARÁ0
211998-03-01PERNAMBUCO0
221998-03-01RIO GRANDE DO SUL0
231998-04-01CEARÁ0
241998-04-01PARANÁ0
251998-04-01PARAÍBA0
261998-04-01PARÁ0
271998-05-01ALAGOAS0
281998-05-01AMAPÁ0
291998-05-01MARANHÃO0
301998-05-01MATO GROSSO DO SUL0
311998-05-01RIO GRANDE DO SUL0
321998-05-01TOCANTINS0
331998-06-01ESPÍRITO SANTO6
341998-06-01RIO DE JANEIRO3
351998-06-01RIO GRANDE DO NORTE1
361998-06-01SÃO PAULO451
371998-07-01ESPÍRITO SANTO37
381998-07-01MARANHÃO274
391998-07-01MATO GROSSO360
401998-07-01MATO GROSSO DO SUL3712
411998-07-01PARAÍBA0
421998-07-01PARÁ638
431998-07-01RONDÔNIA365
441998-07-01SÃO PAULO596
451998-08-01ALAGOAS1
461998-08-01BAHIA815
471998-08-01DISTRITO FEDERAL48
481998-08-01ESPÍRITO SANTO38
491998-08-01MARANHÃO1176
501998-08-01MATO GROSSO228
511998-08-01MINAS GERAIS875
521998-08-01PIAUÍ711
531998-08-01RIO GRANDE DO SUL9
541998-08-01RORAIMA0
551998-08-01SERGIPE0
561998-09-01AMAPÁ20
571998-09-01DISTRITO FEDERAL33
581998-09-01PIAUÍ1991
591998-09-01RORAIMA2
601998-10-01AMAZONAS83
611998-10-01GOIÁS1034
621998-10-01MATO GROSSO576
631998-10-01PARAÍBA179
641998-10-01PARÁ3665
651998-10-01PIAUÍ2586
661998-10-01SERGIPE0
671998-11-01ALAGOAS19
681998-11-01AMAPÁ131
691998-11-01CEARÁ575
701998-11-01DISTRITO FEDERAL0
711998-11-01MARANHÃO2237
721998-11-01RIO DE JANEIRO6
731998-11-01RIO GRANDE DO SUL28
741998-11-01SÃO PAULO488
751998-12-01BAHIA82
761998-12-01MARANHÃO1399
771998-12-01MATO GROSSO100
781998-12-01PARAÍBA51
791998-12-01PERNAMBUCO59
801998-12-01RIO DE JANEIRO1
811998-12-01RONDÔNIA33
821998-12-01TOCANTINS9
831999-01-01ALAGOAS58
841999-01-01GOIÁS14
851999-01-01MATO GROSSO239
861999-01-01MINAS GERAIS36
871999-01-01PARÁ87
881999-01-01PERNAMBUCO102
891999-01-01RONDÔNIA1
901999-01-01SÃO PAULO7
911999-01-01TOCANTINS36
921999-02-01ACRE0
931999-02-01CEARÁ16
941999-02-01MATO GROSSO69
951999-02-01MATO GROSSO DO SUL28
961999-02-01PERNAMBUCO13
971999-02-01RONDÔNIA1
981999-02-01SANTA CATARINA2
991999-02-01TOCANTINS1
1001999-03-01AMAPÁ2
Rows: 1-100 | Columns: 3

Note

VerticaPy 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 VerticaPy 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 vDataFrame.plot():

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

Now we can plot the ACF and PACF plots together:

from verticapy.machine_learning.model_selection import plot_acf_pacf

plot_acf_pacf(
    amazon,
    column = "number",
    ts = "date",
    p = 40,
)
acf
pacf
confidence
01.01.00.1267795309147783
10.4956792887341580.4956792887341580.155151538705701
2-0.00902491738328761-0.3415215874470860.1671963954865323
3-0.1394474068519020.04856076825454380.16777918642512535
4-0.159024465260942-0.1396520840760080.17002131965100242
5-0.162108279852924-0.06440758434678550.17078344960052913
6-0.163813499381328-0.1124559514997650.17236347056339854
7-0.163181448364772-0.1035817559847840.17375997964460396
8-0.160277838551237-0.1240719670939910.17559961328561075
9-0.141430259231878-0.1115731329323770.1771584660187362
10-0.02702935807165820.01577335839590320.1775683591823975
110.3624894726136690.424796112722240.194292298973478
120.7616920911242740.5787228930434170.22192638408213544
130.376751291771019-0.371200258214240.23270890340132178
14-0.03383098684483870.1737624844776210.23542537798173727
15-0.143226889918242-0.1278164009110050.23713473329393076
16-0.1600502898288990.03214057411414650.2377406931331342
17-0.162685637693094-0.05193619585815860.2384713493358544
18-0.164133347280837-0.01012254251359620.23901772010284472
19-0.164349761269233-0.0358382999094680.2396539247266604
20-0.162199819237328-0.02549866277145970.2402479321856056
21-0.144610982270813-0.03382039385563020.24088201802830564
22-0.02637061301038190.02545025231946010.24148389480300914
230.3967989549494230.3718512354200110.25199741876215975
240.7809281604489290.2197771150274040.25597677160283533
250.36100402688506-0.1719463867614640.2586343799736745
26-0.05738610089600890.05623067540738740.2594606669387884
27-0.152954415331713-0.04372776448857060.26020507213758454
28-0.1612244955954040.009935560983963340.2608278334856459
29-0.163416632062352-0.02066184137342890.2614779824787076
30-0.165039473595857-0.004855735695690750.26210443485045803
31-0.165166417431331-0.0162161699711850.2627522222205266
32-0.163084947808881-0.004549745441298650.26338758326190487
33-0.147449429124974-0.03062777588610390.26409234538178394
34-0.0505904416909773-0.04169772436203440.26485873151048966
350.293491135087829-0.07382735732871640.26589338723570816
360.6479296564738520.0863301808248580.2670760843095934
370.295423355893792-0.07967820223320480.26818690615294377
38-0.06073196459402860.07412513625901460.26924351205813934
39-0.154665135387648-0.09541420905318710.2705628403827728
40-0.163256344948950.05080332300307440.2714254162225946
Rows: 1-41 | Columns: 4

See also

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