knn_test_function: KNN Test The knn_test_function returns the labels for a test...

Description Usage Arguments Value See Also Examples

View source: R/FastKNN.R

Description

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

Usage

1
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

1
2
3
4
5
6
7
8
9
# 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)

Example output

  [1] "Good"    "Bad"     "Bad"     "Good"    "Good"    "Good"    "Good"   
  [8] "Average" "Average" "Good"    "Bad"     "Average" "Bad"     "Good"   
 [15] "Good"    "Average" "Good"    "Bad"     "Average" "Average" "Bad"    
 [22] "Bad"     "Average" "Bad"     "Good"    "Good"    "Bad"     "Average"
 [29] "Bad"     "Average" "Average" "Good"    "Good"    "Good"    "Average"
 [36] "Bad"     "Bad"     "Bad"     "Average" "Good"    "Bad"     "Average"
 [43] "Good"    "Average" "Bad"     "Average" "Bad"     "Good"    "Bad"    
 [50] "Good"    "Bad"     "Good"    "Average" "Average" "Bad"     "Good"   
 [57] "Bad"     "Average" "Average" "Bad"     "Average" "Average" "Average"
 [64] "Average" "Bad"     "Good"    "Average" "Average" "Average" "Bad"    
 [71] "Average" "Average" "Bad"     "Bad"     "Average" "Bad"     "Average"
 [78] "Average" "Good"    "Good"    "Average" "Bad"     "Average" "Average"
 [85] "Good"    "Good"    "Bad"     "Good"    "Bad"     "Good"    "Average"
 [92] "Average" "Good"    "Average" "Bad"     "Bad"     "Average" "Bad"    
 [99] "Good"    "Good"   

FastKNN documentation built on May 1, 2019, 8:16 p.m.