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: str | list[str] | 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 fromverticapy
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()
📅dateDateAbcstateVarchar(32)123numberInteger1 1998-01-01 ACRE 0 2 1998-01-01 ALAGOAS 0 3 1998-01-01 AMAPÁ 0 4 1998-01-01 AMAZONAS 0 5 1998-01-01 BAHIA 0 6 1998-01-01 CEARÁ 0 7 1998-01-01 DISTRITO FEDERAL 0 8 1998-01-01 ESPÍRITO SANTO 0 9 1998-01-01 GOIÁS 0 10 1998-01-01 MARANHÃO 0 11 1998-01-01 MATO GROSSO 0 12 1998-01-01 MATO GROSSO DO SUL 0 13 1998-01-01 MINAS GERAIS 0 14 1998-01-01 PARANÁ 0 15 1998-01-01 PARAÍBA 0 16 1998-01-01 PARÁ 0 17 1998-01-01 PERNAMBUCO 0 18 1998-01-01 PIAUÍ 0 19 1998-01-01 RIO DE JANEIRO 0 20 1998-01-01 RIO GRANDE DO NORTE 0 21 1998-01-01 RIO GRANDE DO SUL 0 22 1998-01-01 RONDÔNIA 0 23 1998-01-01 RORAIMA 0 24 1998-01-01 SANTA CATARINA 0 25 1998-01-01 SERGIPE 0 26 1998-01-01 SÃO PAULO 0 27 1998-01-01 TOCANTINS 0 28 1998-02-01 ACRE 0 29 1998-02-01 ALAGOAS 0 30 1998-02-01 AMAPÁ 0 31 1998-02-01 AMAZONAS 0 32 1998-02-01 BAHIA 0 33 1998-02-01 CEARÁ 0 34 1998-02-01 DISTRITO FEDERAL 0 35 1998-02-01 ESPÍRITO SANTO 0 36 1998-02-01 GOIÁS 0 37 1998-02-01 MARANHÃO 0 38 1998-02-01 MATO GROSSO 0 39 1998-02-01 MATO GROSSO DO SUL 0 40 1998-02-01 MINAS GERAIS 0 41 1998-02-01 PARANÁ 0 42 1998-02-01 PARAÍBA 0 43 1998-02-01 PARÁ 0 44 1998-02-01 PERNAMBUCO 0 45 1998-02-01 PIAUÍ 0 46 1998-02-01 RIO DE JANEIRO 0 47 1998-02-01 RIO GRANDE DO NORTE 0 48 1998-02-01 RIO GRANDE DO SUL 0 49 1998-02-01 RONDÔNIA 0 50 1998-02-01 RORAIMA 0 51 1998-02-01 SANTA CATARINA 0 52 1998-02-01 SERGIPE 0 53 1998-02-01 SÃO PAULO 0 54 1998-02-01 TOCANTINS 0 55 1998-03-01 ACRE 0 56 1998-03-01 ALAGOAS 0 57 1998-03-01 AMAPÁ 0 58 1998-03-01 AMAZONAS 0 59 1998-03-01 BAHIA 0 60 1998-03-01 CEARÁ 0 61 1998-03-01 DISTRITO FEDERAL 0 62 1998-03-01 ESPÍRITO SANTO 0 63 1998-03-01 GOIÁS 0 64 1998-03-01 MARANHÃO 0 65 1998-03-01 MATO GROSSO 0 66 1998-03-01 MATO GROSSO DO SUL 0 67 1998-03-01 MINAS GERAIS 0 68 1998-03-01 PARANÁ 0 69 1998-03-01 PARAÍBA 0 70 1998-03-01 PARÁ 0 71 1998-03-01 PERNAMBUCO 0 72 1998-03-01 PIAUÍ 0 73 1998-03-01 RIO DE JANEIRO 0 74 1998-03-01 RIO GRANDE DO NORTE 0 75 1998-03-01 RIO GRANDE DO SUL 0 76 1998-03-01 RONDÔNIA 0 77 1998-03-01 RORAIMA 0 78 1998-03-01 SANTA CATARINA 0 79 1998-03-01 SERGIPE 0 80 1998-03-01 SÃO PAULO 0 81 1998-03-01 TOCANTINS 0 82 1998-04-01 ACRE 0 83 1998-04-01 ALAGOAS 0 84 1998-04-01 AMAPÁ 0 85 1998-04-01 AMAZONAS 0 86 1998-04-01 BAHIA 0 87 1998-04-01 CEARÁ 0 88 1998-04-01 DISTRITO FEDERAL 0 89 1998-04-01 ESPÍRITO SANTO 0 90 1998-04-01 GOIÁS 0 91 1998-04-01 MARANHÃO 0 92 1998-04-01 MATO GROSSO 0 93 1998-04-01 MATO GROSSO DO SUL 0 94 1998-04-01 MINAS GERAIS 0 95 1998-04-01 PARANÁ 0 96 1998-04-01 PARAÍBA 0 97 1998-04-01 PARÁ 0 98 1998-04-01 PERNAMBUCO 0 99 1998-04-01 PIAUÍ 0 100 1998-04-01 RIO DE JANEIRO 0 Rows: 1-100 | Columns: 3Note
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 0 1.0 1.0 0.1267795309147783 1 0.495679288734158 0.495679288734158 0.155151538705701 2 -0.00902491738328761 -0.341521587447086 0.1671963954865323 3 -0.139447406851902 0.0485607682545438 0.16777918642512535 4 -0.159024465260942 -0.139652084076008 0.17002131965100242 5 -0.162108279852924 -0.0644075843467855 0.17078344960052913 6 -0.163813499381328 -0.112455951499765 0.17236347056339854 7 -0.163181448364772 -0.103581755984784 0.17375997964460396 8 -0.160277838551237 -0.124071967093991 0.17559961328561075 9 -0.141430259231878 -0.111573132932377 0.1771584660187362 10 -0.0270293580716582 0.0157733583959032 0.1775683591823975 11 0.362489472613669 0.42479611272224 0.194292298973478 12 0.761692091124274 0.578722893043417 0.22192638408213544 13 0.376751291771019 -0.37120025821424 0.23270890340132178 14 -0.0338309868448387 0.173762484477621 0.23542537798173727 15 -0.143226889918242 -0.127816400911005 0.23713473329393076 16 -0.160050289828899 0.0321405741141465 0.2377406931331342 17 -0.162685637693094 -0.0519361958581586 0.2384713493358544 18 -0.164133347280837 -0.0101225425135962 0.23901772010284472 19 -0.164349761269233 -0.035838299909468 0.2396539247266604 20 -0.162199819237328 -0.0254986627714597 0.2402479321856056 21 -0.144610982270813 -0.0338203938556302 0.24088201802830564 22 -0.0263706130103819 0.0254502523194601 0.24148389480300914 23 0.396798954949423 0.371851235420011 0.25199741876215975 24 0.780928160448929 0.219777115027404 0.25597677160283533 25 0.36100402688506 -0.171946386761464 0.2586343799736745 26 -0.0573861008960089 0.0562306754073874 0.2594606669387884 27 -0.152954415331713 -0.0437277644885706 0.26020507213758454 28 -0.161224495595404 0.00993556098396334 0.2608278334856459 29 -0.163416632062352 -0.0206618413734289 0.2614779824787076 30 -0.165039473595857 -0.00485573569569075 0.26210443485045803 31 -0.165166417431331 -0.016216169971185 0.2627522222205266 32 -0.163084947808881 -0.00454974544129865 0.26338758326190487 33 -0.147449429124974 -0.0306277758861039 0.26409234538178394 34 -0.0505904416909773 -0.0416977243620344 0.26485873151048966 35 0.293491135087829 -0.0738273573287164 0.26589338723570816 36 0.647929656473852 0.086330180824858 0.2670760843095934 37 0.295423355893792 -0.0796782022332048 0.26818690615294377 38 -0.0607319645940286 0.0741251362590146 0.26924351205813934 39 -0.154665135387648 -0.0954142090531871 0.2705628403827728 40 -0.16325634494895 0.0508033230030744 0.2714254162225946 Rows: 1-41 | Columns: 4See also
acf()
: ACF plot from avDataFrame
.pacf()
: PACF plot from avDataFrame
.