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]:
<AxesSubplot:xlabel='"date"', ylabel='"passengers"'>
In [5]:
from verticapy.stats import seasonal_decompose

decomposition = seasonal_decompose(passengers, 
                                   "passengers", 
                                   "date",
                                   polynomial_order = 2,
                                   mult = True)
display(decomposition)
📅
date
Date
123
passengers
Int
123
passengers_trend
Float
123
passengers_seasonal
Float
123
passengers_epsilon
Float
11949-01-01112114.0280408597070.8501353423254531.15536255667615
21949-02-01118115.6900606066110.8821313237414511.15625258033391
31949-03-01132117.3660967501510.9457101217738531.1892501982632
41949-04-01129119.0561492903271.023835848834141.05829695500561
51949-05-01121120.7602182271381.09557477944840.914575272399499
61949-06-01135122.4783035605851.141704525092680.96543020834606
71949-07-01148124.2104052906681.149864657674551.0362320267397
81949-08-01148125.9565234173871.117868676258551.05111507184691
91949-09-01136127.7166579407421.054289878226151.01002314478973
101949-10-01119129.4908088607320.9761641511658650.941423777800471
111949-11-01104131.2789761773580.90442522055160.875922119767362
121949-12-01118133.081159890620.8582954749073161.03306728138343
131950-01-01115134.8973600005180.8501353423254531.00278151254438
141950-02-01126136.7275765070520.8821313237414511.04467496042437
151950-03-01141138.5718094102210.9457101217738531.07593537733039
161950-04-01135140.4300587100271.023835848834140.938951930312987
171950-05-01125142.3023244064681.09557477944840.80178142914427
181950-06-01149144.1886064995451.141704525092680.905110496502086
191950-07-01170146.0889049892571.149864657674551.01201036804486
201950-08-01170148.0032198756061.117868676258551.02751216102852
211950-09-01158149.931551158591.054289878226150.999548831409235
221950-10-01133151.873898838210.9761641511658650.897109889738009
231950-11-01114153.8302629144660.90442522055160.819389519154582
241950-12-01140155.8006433873570.8582954749073161.04694041708226
251951-01-01145157.7850402568850.8501353423254531.08097115679071
261951-02-01150159.7834535230480.8821313237414511.06420724593379
271951-03-01178161.7958831858470.9457101217738531.16330741963279
281951-04-01163163.8223292452821.023835848834140.971816292961965
291951-05-01172165.8627917013531.09557477944840.946536683551796
301951-06-01178167.9172705540591.141704525092680.928476494746238
311951-07-01199169.9857658034021.149864657674551.0181078700925
321951-08-01199172.068277449381.117868676258551.03457380574925
331951-09-01184174.1648054919941.054289878226151.00206844586813
341951-10-01162176.2753499312430.9761641511658650.941457185706776
351951-11-01146178.3999107671290.90442522055160.904868684520885
361951-12-01166180.538487999650.8582954749073161.07127621905567
371952-01-01171182.6910816288070.8501353423254531.10100855124648
381952-02-01180184.85769165460.8821313237414511.10382883718317
391952-03-01193187.0383180770290.9457101217738531.09111036979155
401952-04-01181189.2329608960931.023835848834140.934224942460824
411952-05-01183191.4416201117931.09557477944840.872514599777302
421952-06-01218193.664295724131.141704525092680.98594618389933
431952-07-01230195.9009877331021.149864657674551.02104406353842
441952-08-01242198.1516961387091.117868676258551.09251343123325
451952-09-01209200.4164209409531.054289878226150.989129026987771
461952-10-01191202.6951621398320.9761641511658650.965310720813758
471952-11-01172204.9879197353470.90442522055160.927742632802777
481952-12-01194207.2946937274980.8582954749073161.09037709971173
491953-01-01196209.6154841162850.8501353423254531.09987831484757
501953-02-01196211.9502909017070.8821313237414511.04830778405767
511953-03-01236214.2991140837660.9457101217738531.16448417255751
521953-04-01235216.661953662461.023835848834141.05938757592082
531953-05-01229219.038809637791.09557477944840.954272449518939
541953-06-01243221.4296820097551.141704525092680.961206535149543
551953-07-01264223.8345707783571.149864657674551.02572286787026
561953-08-01272226.2534759435941.117868676258551.07543175747877
571953-09-01237228.6863975054671.054289878226150.982987456097118
581953-10-01211231.1333354639760.9761641511658650.935183884342593
591953-11-01180233.5942898191210.90442522055160.851996122660106
601953-12-01201236.0692605709020.8582954749073160.992018553768322
611954-01-01204238.5582477193180.8501353423254531.00588344387249
621954-02-01188241.061251264370.8821313237414510.884091467154869
631954-03-01235243.5782712060580.9457101217738531.02016702411449
641954-04-01227246.1093075443821.023835848834140.90088112279118
651954-05-01234248.6543602793411.09557477944840.858969517422285
661954-06-01264251.2134294109371.141704525092680.920465154301832
671954-07-01302253.7865149391681.149864657674551.03488400674893
681954-08-01293256.3736168640351.117868676258551.02235918479967
691954-09-01259258.9747351855381.054289878226150.948598272370131
701954-10-01229261.5898699036760.9761641511658650.896791959861755
711954-11-01203264.2190210184510.9044252205515990.849492002088961
721954-12-01229266.8621885298610.8582954749073160.999796509368645
731955-01-01242269.5193724379070.8501353423254531.05617846442999
741955-02-01233272.1905727425880.8821313237414510.970397340910711
751955-03-01267274.8757894439060.9457101217738531.02710947237432
761955-04-01269277.5750225418591.023835848834140.946545650691677
771955-05-01270280.2882720364491.09557477944840.879258978768822
781955-06-01315283.0155379276741.141704525092680.97486965430864
791955-07-01364285.7568202155341.149864657674551.10779156345745
801955-08-01347288.5121189000311.117868676258551.0759067383181
811955-09-01312291.2814339811631.054289878226151.01597203262628
821955-10-01274294.0647654589320.9761641511658650.954519307335023
831955-11-01237296.8621133333360.9044252205515990.882715813208691
841955-12-01278299.6734776043750.8582954749073161.0808356610778
851956-01-01284302.4988582720510.8501353423254531.10434947467745
861956-02-01277305.3382553363620.8821313237414511.0284076664753
871956-03-01317308.191668797310.9457101217738531.08762787713421
881956-04-01313311.0590986548931.023835848834140.982813461528788
891956-05-01318313.9405449091111.09557477944840.924565505078088
901956-06-01374316.8360075599661.141704525092681.03391145664116
911956-07-01413319.7454866074561.149864657674551.12330813254738
921956-08-01405322.6689820515831.117868676258551.12281192700754
931956-09-01355325.6064938923451.054289878226151.03413028805787
941956-10-01306328.5580221297420.9761641511658650.954083744566332
951956-11-01271331.5235667637760.9044252205515990.903820567972856
961956-12-01306334.5031277944460.8582954749073161.06582136238505
971957-01-01315337.4967052217510.8501353423254531.09787512462987
981957-02-01301340.5042990456920.8821313237414511.00209905441883
991957-03-01356343.5259092662690.9457101217738531.09580294411067
1001957-04-01348346.5615358834811.023835848834140.980773114758087
Rows: 1-100 | Columns: 5
In [6]:
decomposition["passengers_trend"].plot(ts = "date",)
decomposition["passengers_seasonal"].plot(ts = "date",)
decomposition["passengers_epsilon"].plot(ts = "date",)
Out[6]:
<AxesSubplot:xlabel='"date"', ylabel='"passengers_epsilon"'>