Why can't character variables be used in fit
in my tidymodels example below? both should equal "ridership"
library(tidymodels)
tidymodels_prefer()
data(Chicago)
#Try to predict ridership variable from the variables 'Clark_Lake' & 'Quincy_Wells'
n <- nrow(Chicago)
Chicago <- Chicago %>% select(ridership, Clark_Lake, Quincy_Wells) #Subset
#Split into training and testing sets
Chicago_train <- Chicago[1:(n - 7), ]
Chicago_test <- Chicago[(n - 6):n, ]
#Model specs
bt_reg_spec <-
boost_tree(trees = 15) %>%
# This model can be used for classification or regression, so set mode
set_mode("regression") %>%
set_engine("xgboost")
bt_reg_spec
#ORIGINAL method (from Tidymodels tutorial):
bt_reg_fit <- bt_reg_spec %>% fit(ridership ~ ., data = Chicago_train)
predict(bt_reg_fit, Chicago_test)
#This way doesn't work:
myvar <- "ridership"
bt_reg_fit <- bt_reg_spec %>% fit(myvar ~ ., data = Chicago_train) #Doesn't work