setup_KNN: Setup KNN Hyperparameters

View source: R/070_Hyperparameters.R

setup_KNNR Documentation

Setup KNN Hyperparameters

Description

Setup hyperparameters for k-Nearest Neighbors training.

Usage

setup_KNN(k = 7L, kernel = "optimal", distance = 2, scale = TRUE, ifw = FALSE)

Arguments

k

(Tunable) Integer [1, Inf): Number of neighbors. Must be less than the number of training cases.

kernel

(Tunable) Character {"rectangular", "triangular", "epanechnikov", "biweight", "triweight", "cos", "inv", "gaussian", "rank", "optimal"}: Kernel used to weight neighbors by distance.

distance

(Tunable) Numeric (0, Inf): Parameter of the Minkowski distance.

scale

Logical: If TRUE, scale features to unit variance before computing distances.

ifw

(Tunable) Logical: If TRUE, use Inverse Frequency Weighting in classification.

Details

Both outcome types are fit with kknn::train.kknn, which selects between regression and classification from the outcome. Factors are one-hot encoded by rtemis first, as an algorithm-internal preprocessor that is re-applied at predict time: the backend's own factor handling resolves a contrast function off the search path, which is not reachable when kknn is loaded but not attached, as a suggested package is.

kknn provides no case weights, so ifw cannot be honored: enabling it makes training abort.

Value

KNNHyperparameters object.

Author(s)

EDG

Examples

knn_hyperparams <- setup_KNN(k = 11L, kernel = "rectangular")
knn_hyperparams

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.