rmse(., truth = variable, estimate = .pred) 中的错误:R Tidymodels(标准)中未使用的参数(truth =,estimate = .pred)

Error in rmse(., truth = variable, estimate = .pred) : unused arguments (truth = , estimate = .pred) in R Tidymodels (yardstick)

我正在拟合一个回归树模型,使用这个 Tidymodels tutorial

# Create a specification
tree_spec <- decision_tree() %>% set_engine("rpart")
# Create an engine
reg_tree_spec <- tree_spec %>% set_mode("regression")
# Fit the model
reg_tree_fit <- fit(reg_tree_spec, loan_amount ~ ., kenya_data_df_train)

# Print
reg_tree_fit

欧防风模型对象

适配时间:2.5s n= 56868

node), 分裂, n, 偏差, yval * 表示终端节点

  1. root 56868 32009190000 455.2222
  2. lender_count< 728.5 56859 13948640000 448.2417
  3. lender_count< 81.5 56613 6692397000 428.2886
  4. lender_count< 20.5 47772 2345794000 342.4569
  5. lender_count< 12.5 35164 1238679000 282.1622 *
  6. lender_count>=12.5 12608 622737900 510.6202 *
  7. lender_count>=20.5 8841 2092969000 892.0767
  8. lender_count< 38.5 7455 740153600 787.4748 *
  9. lender_count>=38.5 1386 832502400 1454.7080 *
  10. lender_count>=81.5 246 2046660000 5040.1420
  11. lender_count< 229 224 938017600 4421.3170 *
  12. lender_count>=229 22 149470700 11340.9100 *
  13. lender_count>=728.5 9 554222200 44555.5600 *

但是我在使用测试数据时收到一个奇怪的错误。

# Evaluate on test data
augment(reg_tree_fit, new_data = kenya_data_df_test) %>%
  rmse(truth = loan_amount, estimate = .pred)
Error in rmse(., truth = loan_amount, estimate = .pred) : 
unused arguments (truth = loan_amount, estimate = .pred)

我的 dput() 火车数据示例:

structure(list(loan_amount = 200, term_in_months = 14, lender_count = 8, 
sector_Agriculture = 1L, sector_Arts = 0L, sector_Clothing = 0L, 
sector_Construction = 0L, sector_Education = 0L, sector_Entertainment = 0L, 
sector_Food = 0L, sector_Health = 0L, sector_Housing = 0L, 
sector_Manufacturing = 0L, sector_Personal_Use = 0L, sector_Retail = 0L, 
sector_Services = 0L, sector_Transportation = 0L, sector_Wholesale = 0L, 
repayment_interval_bullet = 0L, repayment_interval_irregular = 0L, 
repayment_interval_monthly = 1L, repayment_interval_weekly = 0L, 
gender_both = 0L, gender_female = 1L, gender_male = 0L, gender_NA = 0L), row.names = c(NA, 
-1L), class = c("tbl_df", "tbl", "data.frame"), .internal.selfref = <pointer: 
0x000001d8b6f91ef0>)

dput() 用于测试数据。

structure(list(loan_amount = 250, term_in_months = 14, lender_count = 
1, 
sector_Agriculture = 0L, sector_Arts = 0L, sector_Clothing = 0L, 
sector_Construction = 0L, sector_Education = 0L, sector_Entertainment 
= 0L, 
sector_Food = 0L, sector_Health = 0L, sector_Housing = 0L, 
sector_Manufacturing = 0L, sector_Personal_Use = 0L, sector_Retail = 
0L, 
sector_Services = 1L, sector_Transportation = 0L, sector_Wholesale = 
0L, 
repayment_interval_bullet = 0L, repayment_interval_irregular = 1L, 
repayment_interval_monthly = 0L, repayment_interval_weekly = 0L, 
gender_both = 0L, gender_female = 1L, gender_male = 0L, gender_NA = 
0L), row.names = c(NA, 
-1L), class = c("tbl_df", "tbl", "data.frame"), .internal.selfref = 
<pointer: 0x000001d8b6f91ef0>)

已修复上面 akrun 的回答 - yardstick::rmse() 给出了必要的结果。