Loading...

verticapy.machine_learning.vertica.tsa.MA.predict

MA.predict(vdf: Annotated[str | vDataFrame, ''] | None = None, ts: str | None = None, y: Annotated[str | list[str], 'STRING representing one column or a list of columns'] | None = None, start: int | None = None, npredictions: int = 10, output_standard_errors: bool = False, output_index: bool = False, output_estimated_ts: bool = False, freq: Literal[None, 'm', 'months', 'y', 'year', 'infer'] = 'infer', filter_step: int | None = None, method: Literal['auto', 'forecast'] = 'auto', use_index_as_suffix: bool = False) vDataFrame

Predicts using the input relation.

Parameters

vdf: SQLRelation

Object used to run the prediction. You can also specify a customized relation, but you must enclose it with an alias. For example, (SELECT 1) x is valid, whereas (SELECT 1) and SELECT 1 are invalid.

ts: str

TS (Time Series) :py:class`vDataColumn` used to order the data. The :py:class`vDataColumn` type must be date (date, datetime, timestamp…) or numerical.

y: SQLColumns, optional

Response column.

In the case of multivariate analysis, it represents a list of all the predictors.

start: int, optional

The behavior of the start parameter and its range of accepted values depends on whether you provide a timeseries-column (ts):

  • No provided timeseries-column:

    start must be an integer greater or equal to 0, where zero indicates to start prediction at the end of the in-sample data. If start is a positive value, the function predicts the values between the end of the in-sample data and the start index, and then uses the predicted values as time series inputs for the subsequent npredictions.

  • timeseries-column provided:

    start must be an integer greater or equal to 1 and identifies the index (row) of the timeseries-column at which to begin prediction. If the start index is greater than the number of rows, N, in the input data, the function predicts the values between N and start and uses the predicted values as time series inputs for the subsequent npredictions.

Default:

  • No provided timeseries-column:

    prediction begins from the end of the in-sample data.

  • timeseries-column provided:

    prediction begins from the end of the provided input data.

npredictions: int, optional

integer greater or equal to 1, the number of predicted timesteps.

output_standard_errors: bool, optional

boolean, whether to return estimates of the standard error of each prediction.

output_index: bool, optional

boolean, whether to return the index of each position.

output_estimated_ts: bool, optional

Boolean, whether to return the estimated abscissa of each prediction. The real one is hard to obtain due to interval computations.

freq: str, optional

How to compute the delta.

  • m/month:

    We assume that the data is organized on a monthly basis.

  • y/year:

    We assume that the data is organized on a yearly basis.

  • infer:

    When making inferences, the system will attempt to identify the best option, which may involve more computational resources.

  • None:

    The inference is based on the average of the difference between ts and its lag.

filter_step: int, optional

Integer parameter that determines the frequency of predictions. You can adjust it according to your specific requirements, such as setting it to 3 for predictions every third step.

Note

It is only utilized when output_estimated_ts=True.

method: str, optional

Forecasting method. One of the following:

  • auto:

    the model initially utilizes the true values at each step for forecasting. However, when it reaches a point where it can no longer rely on true values, it transitions to using its own predictions for further forecasting. This method is often referred to as “one step ahead” forecasting.

  • forecast:

    the model initiates forecasting from an initial value and entirely disregards any subsequent true values. This approach involves forecasting based solely on the model’s own predictions and does not consider actual observations after the start point.

use_index_as_suffix: bool, optional

[Only used for multivariates models] If set to True, indexes are used as suffix instead of predictors names.

Returns

vDataFrame

a new object.

Examples

We import verticapy:

import verticapy as vp

For this example, we will use the airline passengers dataset.

import verticapy.datasets as vpd

data = vpd.load_airline_passengers()
📅
date
Date
123
passengers
Integer
11949-06-01135
21950-05-01125
31950-09-01158
41950-11-01114
51951-02-01150
61951-04-01163
71951-05-01172
81951-07-01199
91951-11-01146
101952-02-01180
111952-07-01230
121953-02-01196
131953-03-01236
141953-07-01264
151953-10-01211
161954-10-01229
171955-02-01233
181955-09-01312
191955-12-01278
201956-01-01284
211956-02-01277
221956-09-01355
231957-05-01355
241957-09-01404
251958-05-01363
261958-10-01359
271959-02-01342
281959-04-01396
291959-08-01559
301959-10-01407
311959-11-01362
321960-05-01472
331960-09-01508
341960-10-01461
351960-12-01432
361949-03-01132
371949-05-01121
381949-07-01148
391949-08-01148
401949-10-01119
411950-02-01126
421950-03-01141
431950-04-01135
441950-08-01170
451950-12-01140
461951-06-01178
471951-08-01199
481951-10-01162
491952-01-01171
501952-03-01193
511952-04-01181
521952-08-01242
531953-04-01235
541953-05-01229
551953-09-01237
561953-11-01180
571954-01-01204
581954-04-01227
591954-06-01264
601954-07-01302
611954-08-01293
621954-09-01259
631954-11-01203
641955-03-01267
651955-05-01270
661955-10-01274
671955-11-01237
681956-05-01318
691956-06-01374
701956-07-01413
711956-08-01405
721956-11-01271
731957-03-01356
741957-04-01348
751957-07-01465
761957-11-01305
771958-01-01340
781958-03-01362
791958-06-01435
801958-07-01491
811958-08-01505
821959-05-01420
831960-01-01417
841949-02-01118
851949-04-01129
861949-11-01104
871950-07-01170
881950-10-01133
891951-01-01145
901951-03-01178
911951-09-01184
921951-12-01166
931952-06-01218
941952-09-01209
951952-10-01191
961952-12-01194
971953-08-01272
981953-12-01201
991954-03-01235
1001954-05-01234
Rows: 1-100 | Columns: 2

First we import the model:

from verticapy.machine_learning.vertica.tsa import ARIMA

Then we can create the model:

model = ARIMA(order = (12, 1, 2))

We can now fit the model:

model.fit(data, "date", "passengers")


============
coefficients
============
parameter| value  
---------+--------
  phi_1  |-0.02408
  phi_2  |-0.03398
  phi_3  |-0.02702
  phi_4  |-0.12197
  phi_5  |-0.01651
  phi_6  |-0.21558
  phi_7  |-0.00477
  phi_8  |-0.15146
  phi_9  | 0.04249
 phi_10  |-0.16296
 phi_11  | 0.04043
 phi_12  | 0.86090
 theta_1 | 0.06580
 theta_2 |-0.06794


==============
regularization
==============
none

===============
timeseries_name
===============
"passengers"

==============
timestamp_name
==============
date

==============
missing_method
==============
linear_interpolation

===========
call_string
===========
ARIMA('"public"."_verticapy_tmp_arima_v_mldb_43cce6dc979e11efa8720242ac120002_"', '"public"."_verticapy_tmp_view_v_mldb_43f32702979e11efa8720242ac120002_"', '"passengers"', 'date' USING PARAMETERS p=12, d=1, q=2, missing='linear_interpolation', init_method='Zero', epsilon=1e-06, max_iterations=100);

===============
Additional Info
===============
       Name       |  Value  
------------------+---------
        p         |   12    
        d         |    1    
        q         |    2    
       mean       | 2.23776 
      lambda      | 1.00000 
mean_squared_error|178.86952
rejected_row_count|    0    
accepted_row_count|   144   

Prediction is straight-forward:

model.predict()
123
prediction
Float(22)
1436.808245506626
2411.303769750774
3456.591517112856
4497.165582992911
5523.414142302269
6579.634194756896
7670.753858449996
8648.086244158784
9558.685139438718
10498.606577143251
Rows: 1-10 | Columns: 2

Important

For this example, a specific model is utilized, and it may not correspond exactly to the model you are working with. To see a comprehensive example specific to your class of interest, please refer to that particular class.

Examples: ARIMA; ARMA; AR; MA;