Setup hyperparameters for k-Nearest Neighbors training.
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 rather than silently fit an unweighted model.
Examples
knn_hyperparams <- setup_KNN(k = 11L, kernel = "rectangular")
knn_hyperparams
#> <KNNHyperparameters>
#> hyperparameters:
#> k: <int> 11
#> kernel: <chr> rectangular
#> distance: <nmr> 2.00
#> scale: <lgc> TRUE
#> ifw: <lgc> FALSE
#> tunable_hyperparameters: <chr> k, kernel, distance, ifw
#> fixed_hyperparameters: <chr> scale
#> tuned: <int> -1
#> resampled: <int> 0
#> n_workers: <int> 1
#>
#> No search values defined for tunable hyperparameters.