r descr_models("nearest_neighbor", "kknn")

Tuning Parameters

defaults <- 
  tibble::tibble(parsnip = c("neighbors", "weight_func", "dist_power"),
                 default = c("5L", "'optimal'", "2.0"))

param <-
  nearest_neighbor() %>% 
  set_engine("kknn") %>% 
  make_parameter_list(defaults)

This model has r nrow(param) tuning parameters:

param$item

Parsnip changes the default range for neighbors to c(1, 15) and dist_power to c(1/10, 2).

Translation from parsnip to the original package (regression)

nearest_neighbor(
  neighbors = integer(1),
  weight_func = character(1),
  dist_power = double(1)
) %>%  
  set_engine("kknn") %>% 
  set_mode("regression") %>% 
  translate()

min_rows() will adjust the number of neighbors if the chosen value if it is not consistent with the actual data dimensions.

Translation from parsnip to the original package (classification)

nearest_neighbor(
  neighbors = integer(1),
  weight_func = character(1),
  dist_power = double(1)
) %>% 
  set_engine("kknn") %>% 
  set_mode("classification") %>% 
  translate()

Preprocessing requirements



Examples

The "Fitting and Predicting with parsnip" article contains examples for nearest_neighbor() with the "kknn" engine.

Case weights


Saving fitted model objects


References



tidymodels/parsnip documentation built on Feb. 19, 2025, 2:10 a.m.