knn_past {knnp} | R Documentation |
Predicts values of the time series using k-nearest neighbors algorithm. Values corresponding to instants from initial + 1 to the last one are predicted. The first value predicted, which corresponds to instant initial + 1, is calculated using instants from 1 to instant initial; the second value predicted, which corresponds to instant initial + 2, is predicted using instants from 1 to instant initial + 1; and so on until the last value, which corresponds to instant n (length of the time series), is predicted using instants from 1 to instant n - 1.
Description
Predicts values of the time series using k-nearest neighbors algorithm. Values corresponding to instants from initial + 1 to the last one are predicted. The first value predicted, which corresponds to instant initial + 1, is calculated using instants from 1 to instant initial; the second value predicted, which corresponds to instant initial + 2, is predicted using instants from 1 to instant initial + 1; and so on until the last value, which corresponds to instant n (length of the time series), is predicted using instants from 1 to instant n - 1.
Usage
knn_past(
y,
k,
d,
initial = NULL,
distance = "euclidean",
weight = "proportional",
v = 1,
threads = 1
)
Arguments
y |
A time series or a trained kNN model generated by the knn_param_search_function. In case that a model is provided the rest of parameters will be ignored and all of them will be taken from the model. |
k |
Number of neighbors. |
d |
Length of each of the 'elements'. |
initial |
Variable that determines the limit of the known past for the first instant predicted. |
distance |
Type of metric to evaluate the distance between points. Many metrics are supported: euclidean, manhattan, dynamic time warping, camberra and others. For more information about supported metrics check the values that 'method' argument of function parDist (from parallelDist package) can take as this is the function used to calculate the distances. Link to the package info: https://cran.r-project.org/web/packages/parallelDist Some of the values that this argument can take are "euclidean", "manhattan", "dtw", "camberra", "chord". |
weight |
Type of weight to be used at the time of calculating the predicted value with a weighted mean. Three supported: proportional, average, linear.
|
v |
Variable to be predicted if given multivariate time series. |
threads |
Number of threads to be used when parallelizing, default is 1 |
Value
The predicted value.
Examples
knn_past(AirPassengers, 5, 2)
knn_past(LakeHuron, 3, 6)