Description Usage Arguments Value Examples
Predicts next value of the time series using k-nearest neighbors algorithm.
1 2 3 4 5 6 7 8 9 10 | knn_forecast(
y,
k,
d,
distance = "euclidean",
weight = "proportional",
v = 1,
threads = 1,
h = 1
)
|
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'. |
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 the 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 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 |
h |
Temporal horizon of the prediction (only value 1 is implemented). This parameter is present only for compatibility with the forecast package. |
The predicted value.
1 2 | knn_forecast(AirPassengers, 5, 2)
knn_forecast(LakeHuron, 3, 6)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.