Learn R Programming

superml (version 0.1.0)

KNNTrainer: K Nearest Neighbours Trainer

Description

Trains a k nearest neighbour model using fast search algorithms KNN is a supervised learning algorithm which is used for both regression and classification problems.

Usage

KNNTrainer

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

bst = KNNTrainer$new(k, prob, algorithm, type)
bst$fit_predict(train, test, y)
bst$get_predictions(type)

Methods

$new()

Initialise the instance of the vectorizer

$fit_predict()

trains the knn model and stores the test prediction

$get_predictions()

returns predictions

Arguments

k

number of neighbours to predict

prob

if probability should be computed

algorithm

algorithm used to train the model, possible values are 'kd_tree','cover_tree','brute'

type

type of problem to solve i.e. regression or classification, possible values are 'reg' or 'class'

Examples

Run this code
# NOT RUN {
data("iris")

iris$Species <- as.integer(as.factor(iris$Species))

xtrain <- iris[1:100,]
xtest <- iris[101:150,]

bst <- KNNTrainer$new(k=3, prob=TRUE, type="class")
bst$fit_predict(xtrain, xtest, 'Species')
pred <- bst$get_predictions(type="raw")
# }

Run the code above in your browser using DataLab