Type: | Package |
Title: | Fast k-Nearest Neighbors |
Version: | 0.0.1 |
Date: | 2015-02-11 |
Author: | Gaston Besanson |
Maintainer: | Gaston Besanson <besanson@gmail.com> |
Description: | Compute labels for a test set according to the k-Nearest Neighbors classification. This is a fast way to do k-Nearest Neighbors classification because the distance matrix -between the features of the observations- is an input to the function rather than being calculated in the function itself every time. |
License: | GPL-3 |
Imports: | pdist, assertthat |
Packaged: | 2015-02-12 18:39:41 UTC; DON |
NeedsCompilation: | no |
Repository: | CRAN |
Date/Publication: | 2015-02-12 22:37:24 |
Distance for KNN Test The Distance_for_KNN_test returns the distance matrix between the test set and the training set.
Description
Distance for KNN Test The Distance_for_KNN_test returns the distance matrix between the test set and the training set.
Usage
Distance_for_KNN_test(test_set, train_set)
Arguments
test_set |
is a matrix where the columns are the features of the test set |
train_set |
is a matrix with the features of the training set |
Value
a distance matrix
See Also
knn_test_function
pdist
k-Nearest Neighbors
the k.nearest.neigbors
gives the list of points (k-Neigbours) that are closest
to the row i in descending order.
Description
k-Nearest Neighbors
the k.nearest.neigbors
gives the list of points (k-Neigbours) that are closest
to the row i in descending order.
Usage
k.nearest.neighbors(i, distance_matrix, k = 5)
Arguments
i |
is from the numeric class and is a row from the distance_matrix. |
distance_matrix |
is a nxn matrix. |
k |
is from the numeric class and represent the number of neigbours that the function will return. |
Details
The output of this function is used in the knn_test_function
function.
Value
a k vector with the k closest neigbours to the i observation.
See Also
order
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
# 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)
KNN Training The knn_training_function returns the labels for a training set using the k-Nearest Neighbors Clasification method.
Description
KNN Training The knn_training_function returns the labels for a training set using the k-Nearest Neighbors Clasification method.
Usage
knn_training_function(dataset, distance, label, k = 1)
Arguments
dataset |
is a matrix with the features of the training set |
distance |
is a nxn matrix with the distance between each observation of the training set |
label |
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. |
Details
This function is use to check the quality of the Classifier. Because then the predicted labels are compared with the true labels
Value
a k vector with the predicted labels for the training set. #'
See Also
k.nearest.neighbors
sample