KNNTrainer: K Nearest Neighbours Trainer

Description Usage Format Usage Methods Arguments Examples

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

1

Format

R6Class object.

Usage

For usage details see Methods, Arguments and Examples sections.

1
2
3
bst = KNNTrainer$new(k=1, prob=FALSE, algorithm=NULL, type="class")
bst$fit(X_train, X_test, "target")
bst$predict(type)

Methods

$new()

Initialise the instance of the trainer

$fit()

trains the knn model and stores the test prediction

$predict()

returns predictions

Arguments

k

number of neighbours to predict

prob

if probability should be computed, default=FALSE

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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(xtrain, xtest, 'Species')
pred <- bst$predict(type="raw")

ssi-ashraf/superml documentation built on Nov. 5, 2019, 9:18 a.m.