% set_mode("classification") rf_fit <- fit(rf_spec, class_outcom" /> % set_mode("classification") rf_fit <- fit(rf_spec, class_outcom" /> % set_mode("classification") rf_fit <- fit(rf_spec, class_outcom"/>
rf_spec<-rand_forest(mtry =7 ) %>% 
  set_engine("ranger", importance = 'permutation') %>%
  set_mode("classification")

rf_fit <- fit(rf_spec, class_outcome ~ ., data = NPS_Data_train)

vip(rf_fit)

augment(rf_fit, new_data = NPS_Data_train) %>%
  conf_mat(truth=class_outcome,estimate=.pred_class)

Error in model.frame.default(mod_terms, new_data, na.action = na.action, : factor FAMILY_TYPE has new levels missing

The above error does not make sense as I'm trying to get the confusion matrix on the training data set used to fit the model, there shouldn't be any new levels missing as it is the training set.

I changed FAMILY_TYPE into a factor explicitly, but get the same error

NPS_Data_train$FAMILY_TYPE <- as.factor(NPS_Data_train$FAMILY_TYPE)


  FAMILY_TYPE            n
  <fct>              <int>
1 Couple              9028
2 Family             10085
3 Family Plus          810
4 missing             1605
5 Single             21334
6 Single Parent        967
7 Single Parent Plus    98
0

There are 0 best solutions below