LearnerKnn: LearnerKnn R6 class

LearnerKnnR Documentation

LearnerKnn R6 class

Description

This learner is a wrapper around class::knn() in order to perform a k-nearest neighbor classification.

Details

Optimization metric: classification error rate Can be used with

  • MLTuneParameters

  • MLCrossValidation

  • MLNestedCV

Implemented methods:

  • ⁠$fit⁠ To fit the model.

  • ⁠$predict⁠ To predict new data with the model.

  • ⁠$cross_validation⁠ To perform a grid search (hyperparameter optimization).

  • ⁠$bayesian_scoring_function⁠ To perform a Bayesian hyperparameter optimization.

For the two hyperparameter optimization strategies ("grid" and "bayesian"), the parameter metric_optimization_higher_better of the learner is set to FALSE by default as the mean misclassification error (measures::MMCE()) is used as the optimization metric.

Super class

mlexperiments::MLLearnerBase -> LearnerKnn

Methods

Public methods

Inherited methods

Method new()

Create a new LearnerKnn object.

Usage
LearnerKnn$new()
Details

This learner is a wrapper around class::knn() in order to perform a k-nearest neighbor classification. The following experiments are implemented:

  • MLTuneParameters

  • MLCrossValidation

  • MLNestedCV For the two hyperparameter optimization strategies ("grid" and "bayesian"), the parameter metric_optimization_higher_better of the learner is set to FALSE by default as the mean misclassification error (measures::MMCE()) is used as the optimization metric.

Examples
if (requireNamespace("class", quietly = TRUE)) {
  LearnerKnn$new()
}


Method clone()

The objects of this class are cloneable with this method.

Usage
LearnerKnn$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

class::knn(), measures::MMCE()

class::knn(), measures::MMCE()

Examples

if (requireNamespace("class", quietly = TRUE)) {
  LearnerKnn$new()
}


## ------------------------------------------------
## Method `LearnerKnn$new`
## ------------------------------------------------

if (requireNamespace("class", quietly = TRUE)) {
  LearnerKnn$new()
}


mlexperiments documentation built on Jan. 16, 2026, 5:17 p.m.