seasonal_decompose¶
In [ ]:
seasonal_decompose(vdf: vDataFrame,
column: str,
ts: str,
by: list = [],
period: int = -1,
polynomial_order: int = 1,
estimate_seasonality: bool = True,
rule: (str, datetime.timedelta) = None,
mult: bool = False,
two_sided: bool = False,)
Performs a seasonal time series decomposition.
Parameters¶
| Name | Type | Optional | Description |
|---|---|---|---|
vdf | vDataFrame | ❌ | input vDataFrame. |
column | str | ❌ | Input vcolumn to decompose. |
ts | str | ❌ | vcolumn used as timeline. It will be to use to order the data. It can be a numerical or type date like (date, datetime, timestamp...) vcolumn. |
by | list | ✓ | vcolumns used in the partition. |
period | int | ✓ | Time Series period. It is used to retrieve the seasonality component. if period is lesser or equal to 0, the seasonal component will be estimated using ACF. In this case, polynomial_order must be greater than 0. |
polynomial_order | int | ✓ | If greater than 0, the trend will be estimated using a polynomial of degree 'polynomial_order'. The parameter 'two_sided' will be ignored. If equal to 0, the trend will be estimated using Moving Averages. |
estimate_seasonality | bool | ✓ | If set to True, the seasonality will be estimated using cosine and sine functions. |
rule | str / time | ✓ | Interval to use to slice the time. For example, '5 minutes' will create records separated by '5 minutes' time interval. |
mult | bool | ✓ | If set to True, the decomposition type will be 'multiplicative'. Otherwise, it is 'additive'. |
two_sided | bool | ✓ | If set to True, a centered moving average is used for the trend isolation. Otherwise only past values are used. |
Returns¶
tablesample : An object containing the result. For more information, see utilities.tablesample.
Example¶
In [2]:
%matplotlib inline
from verticapy.datasets import load_airline_passengers
passengers = load_airline_passengers()
passengers.plot(ts = "date", columns = ["passengers"])
Out[2]:
In [5]:
from verticapy.stats import seasonal_decompose
decomposition = seasonal_decompose(passengers,
"passengers",
"date",
polynomial_order = 2,
mult = True)
display(decomposition)
In [6]:
decomposition["passengers_trend"].plot(ts = "date",)
decomposition["passengers_seasonal"].plot(ts = "date",)
decomposition["passengers_epsilon"].plot(ts = "date",)
Out[6]:
