object 'object' not found when fitting knn model

I'm just working through a tutorial so I don't have much familiarity with tidymodels. I'm running into this error when I try to do a very introductory fit and don't know where to go from here. Any ideas?

library(tidymodels)
#> -- Attaching packages ---------------------------------------------------------------------------------------------------- tidymodels 0.1.0.9000 --
#> v broom     0.5.5      v recipes   0.1.10
#> v dials     0.0.6      v rsample   0.0.6 
#> v dplyr     0.8.5      v tibble    3.0.0 
#> v ggplot2   3.3.0      v tune      0.1.0 
#> v infer     0.5.1      v workflows 0.1.1 
#> v parsnip   0.1.0      v yardstick 0.0.6 
#> v purrr     0.3.3
#> -- Conflicts ------------------------------------------------------------------------------------------------------------ tidymodels_conflicts() --
#> x purrr::discard()  masks scales::discard()
#> x dplyr::filter()   masks stats::filter()
#> x dplyr::lag()      masks stats::lag()
#> x ggplot2::margin() masks dials::margin()
#> x recipes::step()   masks stats::step()
library(AmesHousing)
ames <- make_ames() %>% 
  select(-matches("Qu"))

set.seed(4595)
data_split <- initial_split(ames, strata = "Sale_Price")
ames_train <- training(data_split)
ames_test <- testing(data_split)

perf_metrics <- metric_set(rmse, rsq, ccc)

knn_mod <- 
  nearest_neighbor(neighbors = 5) %>% 
  set_engine("kknn") %>% 
  set_mode("regression")

knn_wfl <- 
  workflow() %>% 
  add_model(knn_mod) %>% 
  add_formula(log10(Sale_Price) ~ Longitude + Latitude)

fit(knn_wfl, data = ames_train)
#> Error in eval(parse(text = text, keep.source = FALSE), envir): object 'object' not found

And the solution is....

install.packages("kknn")

You need to have the model you're setting as the engine installed. :laughing:

It was useful to use debug([function-name]) to stop the code, options(error = browser()) to step through it, and the F10 key to step forward copiously till I figured out a function called check_installs couldn't find the "kknn" model.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.