I am learning how to treat with imbalanced data with this article: https://www.r-bloggers.com/dealing-with-unbalanced-data-in-machine-learning/
And Mutate is a simple method to replace original NA values with new values from "dplyr".
Here is the code going wrong:
models <- list(original = model_rf,
under = model_rf_under,
over = model_rf_over,
smote = model_rf_smote,
rose = model_rf_rose)
comparison <- data.frame(model = names(models),
Sensitivity = rep(NA, length(models)),
Specificity = rep(NA, length(models)),
Precision = rep(NA, length(models)),
Recall = rep(NA, length(models)),
F1 = rep(NA, length(models)))
for (name in names(models)) {
model <- get(paste0("cm_", name))
comparison[comparison$model == name, ] <- filter(comparison, model == name) %>%
mutate(Sensitivity = model$byClass["Sensitivity"],
Specificity = model$byClass["Specificity"],
Precision = model$byClass["Precision"],
Recall = model$byClass["Recall"],
F1 = model$byClass["F1"])
}
However, when I run it, I always got the error: $ operator is invalid for atomic vectors. And I double check the code and I find out the problem may come from the function "mutate". And I try to use mutate_ which works.
But I don't know why it works. I am eager to know the differences between mutate() and mutate_() Thanks!