我正在使用本Tidymodels
教程拟合回归树模型。
# 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), split, n, deviance, yval * 表示终端节点
- 根 56868 32009190000 455.2222
- 贷方计数< 728.5 56859 13948640000 448.2417
- 贷方计数< 81.5 56613 6692397000 428.2886
- 贷方计数< 20.5 47772 2345794000 342.4569
- 贷方计数< 12.5 35164 1238679000 282.1622 *
- 贷方计数>=12.5 12608 622737900 510.6202 *
- 贷方计数>=20.5 8841 2092969000 892.0767
- 贷方计数< 38.5 7455 740153600 787.4748 *
- 贷方数> = 38.5 1386 832502400 1454.7080 *
- 贷方数> = 81.5 246 2046660000 5040.1420
- 贷方计数< 229 224 938017600 4421.3170 *
- 贷方数>=229 22 149470700 11340.9100 *
- 贷方数>=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>)