verticapy.vDataFrame.acf¶
- vDataFrame.acf(column: str, ts: str, by: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, p: int | list = 12, unit: str = 'rows', method: Literal['pearson', 'kendall', 'spearman', 'spearmand', 'biserial', 'cramer'] = 'pearson', confidence: bool = True, alpha: float = 0.95, show: bool = True, kind: Literal['line', 'heatmap', 'bar'] = 'bar', mround: int = 3, chart: PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure | None = None, **style_kwargs) PlottingBase | TableSample | Axes | mFigure | Highchart | Highstock | Figure¶
Calculates the correlations between the specified vDataColumn and its various time lags. This function is particularly useful for time series analysis and forecasting as it helps uncover relationships between data points at different time intervals. Understanding these correlations can be vital for making predictions and gaining insights into temporal data patterns.
Parameters¶
- column: str
Input vDataColumn used to compute the Auto Correlation Plot.
- ts: str
TS (Time Series) vDataColumn used to order the data. It can be of type date or a numerical vDataColumn.
- by: SQLColumns, optional
vDataColumns used in the partition.
- p: int | list, optional
Int equal to the maximum number of lag to consider during the computation or List of the different lags to include during the computation. p must be positive or a list of positive integers.
- unit: str, optional
Unit used to compute the lags.
- rows:
Natural lags.
- else:
Any time unit. For example, you can write ‘hour’ to compute the hours lags or ‘day’ to compute the days lags.
- method: str, optional
Method used to compute the correlation.
- pearson:
Pearson’s correlation coefficient (linear).
- spearman:
Spearman’s correlation coefficient (monotonic - rank based).
- spearmanD:
Spearman’s correlation coefficient using the DENSE RANK function instead of the RANK function.
- kendall:
Kendall’s correlation coefficient (similar trends). The method computes the Tau-B coefficient.
Warning
This method uses a CROSS JOIN during computation and is therefore computationally expensive at O(n * n), where n is the total count of the
vDataFrame.
- cramer:
Cramer’s V (correlation between categories).
- biserial:
Biserial Point (correlation between binaries and a numericals).
- confidence: bool, optional
If set to True, the confidence band width is drawn.
- alpha: float, optional
Significance Level. Probability to accept H0. Only used to compute the confidence band width.
- show: bool, optional
If set to True, the Plotting object is returned.
- kind: str, optional
ACF Type.
- bar:
Classical Autocorrelation Plot using bars.
- heatmap:
Draws the ACF heatmap.
- line:
Draws the ACF using a Line Plot.
- mround: int, optional
Round the coefficient using the input number of digits. It is used only to display the ACF Matrix (kind must be set to ‘heatmap’).
- chart: PlottingObject, optional
The chart object used to plot.
- **style_kwargs
Any optional parameter to pass to the plotting functions.
Returns¶
- obj
Plotting Object.
Examples¶
Import the amazon dataset from VerticaPy.
from verticapy.datasets import load_amazon data = load_amazon()
📅dateAbcstate123number1 1998-01-01 AMAPÁ 0 2 1998-01-01 AMAZONAS 0 3 1998-01-01 DISTRITO FEDERAL 0 4 1998-01-01 ESPÍRITO SANTO 0 5 1998-01-01 MARANHÃO 0 6 1998-01-01 PARANÁ 0 7 1998-01-01 PIAUÍ 0 8 1998-01-01 RORAIMA 0 9 1998-01-01 SERGIPE 0 10 1998-01-01 SÃO PAULO 0 11 1998-02-01 GOIÁS 0 12 1998-02-01 MATO GROSSO DO SUL 0 13 1998-02-01 MINAS GERAIS 0 14 1998-02-01 PARAÍBA 0 15 1998-02-01 SANTA CATARINA 0 16 1998-02-01 SÃO PAULO 0 17 1998-03-01 AMAPÁ 0 18 1998-03-01 BAHIA 0 19 1998-03-01 MATO GROSSO DO SUL 0 20 1998-03-01 PARÁ 0 21 1998-03-01 PERNAMBUCO 0 22 1998-03-01 RIO GRANDE DO SUL 0 23 1998-04-01 CEARÁ 0 24 1998-04-01 PARANÁ 0 25 1998-04-01 PARAÍBA 0 26 1998-04-01 PARÁ 0 27 1998-05-01 ALAGOAS 0 28 1998-05-01 AMAPÁ 0 29 1998-05-01 MARANHÃO 0 30 1998-05-01 MATO GROSSO DO SUL 0 31 1998-05-01 RIO GRANDE DO SUL 0 32 1998-05-01 TOCANTINS 0 33 1998-06-01 ESPÍRITO SANTO 6 34 1998-06-01 RIO DE JANEIRO 3 35 1998-06-01 RIO GRANDE DO NORTE 1 36 1998-06-01 SÃO PAULO 451 37 1998-07-01 ESPÍRITO SANTO 37 38 1998-07-01 MARANHÃO 274 39 1998-07-01 MATO GROSSO 360 40 1998-07-01 MATO GROSSO DO SUL 3712 41 1998-07-01 PARAÍBA 0 42 1998-07-01 PARÁ 638 43 1998-07-01 RONDÔNIA 365 44 1998-07-01 SÃO PAULO 596 45 1998-08-01 ALAGOAS 1 46 1998-08-01 BAHIA 815 47 1998-08-01 DISTRITO FEDERAL 48 48 1998-08-01 ESPÍRITO SANTO 38 49 1998-08-01 MARANHÃO 1176 50 1998-08-01 MATO GROSSO 228 51 1998-08-01 MINAS GERAIS 875 52 1998-08-01 PIAUÍ 711 53 1998-08-01 RIO GRANDE DO SUL 9 54 1998-08-01 RORAIMA 0 55 1998-08-01 SERGIPE 0 56 1998-09-01 AMAPÁ 20 57 1998-09-01 DISTRITO FEDERAL 33 58 1998-09-01 PIAUÍ 1991 59 1998-09-01 RORAIMA 2 60 1998-10-01 AMAZONAS 83 61 1998-10-01 GOIÁS 1034 62 1998-10-01 MATO GROSSO 576 63 1998-10-01 PARAÍBA 179 64 1998-10-01 PARÁ 3665 65 1998-10-01 PIAUÍ 2586 66 1998-10-01 SERGIPE 0 67 1998-11-01 ALAGOAS 19 68 1998-11-01 AMAPÁ 131 69 1998-11-01 CEARÁ 575 70 1998-11-01 DISTRITO FEDERAL 0 71 1998-11-01 MARANHÃO 2237 72 1998-11-01 RIO DE JANEIRO 6 73 1998-11-01 RIO GRANDE DO SUL 28 74 1998-11-01 SÃO PAULO 488 75 1998-12-01 BAHIA 82 76 1998-12-01 MARANHÃO 1399 77 1998-12-01 MATO GROSSO 100 78 1998-12-01 PARAÍBA 51 79 1998-12-01 PERNAMBUCO 59 80 1998-12-01 RIO DE JANEIRO 1 81 1998-12-01 RONDÔNIA 33 82 1998-12-01 TOCANTINS 9 83 1999-01-01 ALAGOAS 58 84 1999-01-01 GOIÁS 14 85 1999-01-01 MATO GROSSO 239 86 1999-01-01 MINAS GERAIS 36 87 1999-01-01 PARÁ 87 88 1999-01-01 PERNAMBUCO 102 89 1999-01-01 RONDÔNIA 1 90 1999-01-01 SÃO PAULO 7 91 1999-01-01 TOCANTINS 36 92 1999-02-01 ACRE 0 93 1999-02-01 CEARÁ 16 94 1999-02-01 MATO GROSSO 69 95 1999-02-01 MATO GROSSO DO SUL 28 96 1999-02-01 PERNAMBUCO 13 97 1999-02-01 RONDÔNIA 1 98 1999-02-01 SANTA CATARINA 2 99 1999-02-01 TOCANTINS 1 100 1999-03-01 AMAPÁ 2 Rows: 1-100 | Columns: 3Draw the ACF Plot.
data.acf( column = "number", ts = "date", by = "state", method = "pearson", p = 24, )
For more examples, please look at the Auto-Correlation Plot page of the Chart Gallery.
See also
vDataFrame.pacf(): Computes the partial autocorrelations.