Learn R Programming

mlmts (version 1.1.2)

knn_classifier: Constructs a nearest neighbours-based classifier and returns the predictions for a test set

Description

knn_classifier returns the predictions for a test set concerning a nearest neighbours-based classifier.

Usage

knn_classifier(dataset, classes, index_test, distance, k, ...)

Value

The class labels for the elements in the test set.

Arguments

dataset

A list of MTS (numerical matrices).

classes

A vector containing the class labels associated with the elements in dataset.

index_test

The indexes associated with the test elements in dataset, i.e., the elements for which predictions will be computed.

distance

The corresponding distance measure to compute the nearest neighbours-based classifier (must be one the functions implemented in mlmts, as a string).

k

The number of neighbours.

...

Additional parameters for the function with respect to the considered distance.

Author

Ángel López-Oriona, José A. Vilar

Details

Given a collection of MTS containing the training and test set, the function constructs a nearest neighbours-based classifier based on a given dissimilarity measure. The corresponding predictions for the elements in the test set are returned.

Examples

Run this code
predictions_1_nn <- knn_classifier(BasicMotions$data[1 : 10], BasicMotions$classes[1 : 10],
index_test = 6 : 10, distance = 'dis_modwt', k = 1) # Computing the
# predictions for the test elements in dataset BasicMotions according to
# a 1-nearest neighbour classifier based on dis_modtw.
predictions_1_nn

Run the code above in your browser using DataLab