Learn R Programming

FastKNN (version 0.0.1)

knn_test_function: KNN Test The knn_test_function returns the labels for a test set using the k-Nearest Neighbors Clasification method.

Description

KNN Test The knn_test_function returns the labels for a test set using the k-Nearest Neighbors Clasification method.

Usage

knn_test_function(dataset, test, distance, labels, k = 3)

Arguments

dataset
is a matrix with the features of the training set
test
is a matrix where the columns are the features of the test set
distance
is a nxn matrix with the distance between each observation of the test set and the training set
labels
is a nx1 vector with the labels of the training set
k
is from the numeric class and represent the number of neigbours to be use in the classifier.

Value

a k vector with the predicted labels for the test set.

See Also

k.nearest.neighbors

sample

Examples

Run this code
# Create Data for restaurant reviews
training <- matrix(rexp(600,1), ncol=2)
test  <- matrix(rexp(200,1), ncol=2)
# Label "Good", "Bad", "Average"
labelsExample <- c(rep("Good",100), rep("Bad",100), rep("Average",100))
# Distance Matrix
distanceExample<-Distance_for_KNN_test(test, training)
# KNN
knn_test_function(training, test, distanceExample,labelsExample, k = 3)

Run the code above in your browser using DataLab