verticapy.machine_learning.vertica.tsa.ARIMA.predict¶
- ARIMA.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) xis valid, whereas(SELECT 1)andSELECT 1are 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
listof 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:
startmust be an integer greater or equal to 0, where zero indicates to start prediction at the end of the in-sample data. Ifstartis 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 subsequentnpredictions.
- timeseries-column provided:
startmust be anintegergreater or equal to1and identifies the index (row) of the timeseries-column at which to begin prediction. If thestartindex is greater than the number of rows,N, in the input data, the function predicts the values betweenNandstartand 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
integergreater or equal to1, 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
tsand 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
3for 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()
📅date123passengers1 1949-06-01 135 2 1950-05-01 125 3 1950-09-01 158 4 1950-11-01 114 5 1951-02-01 150 6 1951-04-01 163 7 1951-05-01 172 8 1951-07-01 199 9 1951-11-01 146 10 1952-02-01 180 11 1952-07-01 230 12 1953-02-01 196 13 1953-03-01 236 14 1953-07-01 264 15 1953-10-01 211 16 1954-10-01 229 17 1955-02-01 233 18 1955-09-01 312 19 1955-12-01 278 20 1956-01-01 284 21 1956-02-01 277 22 1956-09-01 355 23 1957-05-01 355 24 1957-09-01 404 25 1958-05-01 363 26 1958-10-01 359 27 1959-02-01 342 28 1959-04-01 396 29 1959-08-01 559 30 1959-10-01 407 31 1959-11-01 362 32 1960-05-01 472 33 1960-09-01 508 34 1960-10-01 461 35 1960-12-01 432 36 1949-03-01 132 37 1949-05-01 121 38 1949-07-01 148 39 1949-08-01 148 40 1949-10-01 119 41 1950-02-01 126 42 1950-03-01 141 43 1950-04-01 135 44 1950-08-01 170 45 1950-12-01 140 46 1951-06-01 178 47 1951-08-01 199 48 1951-10-01 162 49 1952-01-01 171 50 1952-03-01 193 51 1952-04-01 181 52 1952-08-01 242 53 1953-04-01 235 54 1953-05-01 229 55 1953-09-01 237 56 1953-11-01 180 57 1954-01-01 204 58 1954-04-01 227 59 1954-06-01 264 60 1954-07-01 302 61 1954-08-01 293 62 1954-09-01 259 63 1954-11-01 203 64 1955-03-01 267 65 1955-05-01 270 66 1955-10-01 274 67 1955-11-01 237 68 1956-05-01 318 69 1956-06-01 374 70 1956-07-01 413 71 1956-08-01 405 72 1956-11-01 271 73 1957-03-01 356 74 1957-04-01 348 75 1957-07-01 465 76 1957-11-01 305 77 1958-01-01 340 78 1958-03-01 362 79 1958-06-01 435 80 1958-07-01 491 81 1958-08-01 505 82 1959-05-01 420 83 1960-01-01 417 84 1949-02-01 118 85 1949-04-01 129 86 1949-11-01 104 87 1950-07-01 170 88 1950-10-01 133 89 1951-01-01 145 90 1951-03-01 178 91 1951-09-01 184 92 1951-12-01 166 93 1952-06-01 218 94 1952-09-01 209 95 1952-10-01 191 96 1952-12-01 194 97 1953-08-01 272 98 1953-12-01 201 99 1954-03-01 235 100 1954-05-01 234 Rows: 1-100 | Columns: 2First 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_c55b5ea0979d11efa8720242ac120002_"', '"public"."_verticapy_tmp_view_v_mldb_c585b9b6979d11efa8720242ac120002_"', '"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()
123prediction1 436.808245506626 2 411.303769750774 3 456.591517112856 4 497.165582992911 5 523.414142302269 6 579.634194756896 7 670.753858449996 8 648.086244158784 9 558.685139438718 10 498.606577143251 Rows: 1-10 | Columns: 2