I am Fitting a regression tree model, using this 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
parsnip model object
Fit time: 2.5s n= 56868
node), split, n, deviance, yval * denotes terminal node
But I receive a weird error when I use test data.
# 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)
My dput()
example for train data:
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()
for test data.
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>)
Fixed with akrun
's answer above - yardstick::rmse()
gave the necessary result.