Skip to contents

k-Nearest-Neighbor classification. Calls kknn::kknn() from package kknn.

Note

There is no training step for k-NN models, just storing the training data to process it during the predict step. Therefore, $model returns a list with the following elements:

  • formula: Formula for calling kknn::kknn() during $predict().

  • data: Training data for calling kknn::kknn() during $predict().

  • pv: Training parameters for calling kknn::kknn() during $predict().

  • kknn: Model as returned by kknn::kknn(), only available after $predict() has been called.

Dictionary

This Learner can be instantiated via the dictionary mlr_learners or with the associated sugar function lrn():

mlr_learners$get("classif.kknn")
lrn("classif.kknn")

Meta Information

  • Task type: “classif”

  • Predict Types: “response”, “prob”

  • Feature Types: “logical”, “integer”, “numeric”, “factor”, “ordered”

  • Required Packages: mlr3, mlr3learners, kknn

Parameters

IdTypeDefaultRangeLevels
kinteger7\([1, \infty)\)-
distancenumeric2\([0, \infty)\)-
kernelcharacteroptimal-rectangular, triangular, epanechnikov, biweight, triweight, cos, inv, gaussian, rank, optimal
scalelogicalTRUE-TRUE, FALSE
ykernellistNULL--

References

Hechenbichler, Klaus, Schliep, Klaus (2004). “Weighted k-nearest-neighbor techniques and ordinal classification.” Technical Report Discussion Paper 399, SFB 386, Ludwig-Maximilians University Munich. doi: 10.5282/ubm/epub.1769 .

Samworth, J R (2012). “Optimal weighted nearest neighbour classifiers.” The Annals of Statistics, 40(5), 2733--2763. doi: 10.1214/12-AOS1049 .

Cover, Thomas, Hart, Peter (1967). “Nearest neighbor pattern classification.” IEEE transactions on information theory, 13(1), 21--27. doi: 10.1109/TIT.1967.1053964 .

See also

Other Learner: mlr_learners_classif.cv_glmnet, mlr_learners_classif.glmnet, mlr_learners_classif.lda, mlr_learners_classif.log_reg, mlr_learners_classif.multinom, mlr_learners_classif.naive_bayes, mlr_learners_classif.nnet, mlr_learners_classif.qda, mlr_learners_classif.ranger, mlr_learners_classif.svm, mlr_learners_classif.xgboost, mlr_learners_regr.cv_glmnet, mlr_learners_regr.glmnet, mlr_learners_regr.kknn, mlr_learners_regr.km, mlr_learners_regr.lm, mlr_learners_regr.ranger, mlr_learners_regr.svm, mlr_learners_regr.xgboost, mlr_learners_surv.cv_glmnet, mlr_learners_surv.glmnet, mlr_learners_surv.ranger, mlr_learners_surv.xgboost

Super classes

mlr3::Learner -> mlr3::LearnerClassif -> LearnerClassifKKNN

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage


Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerClassifKKNN$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (requireNamespace("kknn", quietly = TRUE)) {
  learner = mlr3::lrn("classif.kknn")
  print(learner)

  # available parameters:
learner$param_set$ids()
}
#> <LearnerClassifKKNN:classif.kknn>
#> * Model: -
#> * Parameters: k=7
#> * Packages: mlr3, mlr3learners, kknn
#> * Predict Type: response
#> * Feature types: logical, integer, numeric, factor, ordered
#> * Properties: multiclass, twoclass
#> [1] "k"        "distance" "kernel"   "scale"    "ykernel"