以下是我的代码,标记的代码显示错误。你能帮我解决这个问题吗?非常感谢!
#Look at the ROC plot for your first model. Based on this plot choose a probability threshold that balances capturing the most correct predictions against false positives. Then generate a new variable in your data set that classifies each student according to your chosen threshold.
threshold.pred1 <- 0.1
#Now generate three diagnostics:
prob <- as.data.frame(predict(rp, newdata = data, type = "p"))
res <- ifelse(prob$yes < threshold.pred1, "yes", "no")
cm = as.matrix(table(Label = data$level.up, Predicted = res))
data$accuracy.model1 <- sum(diag(cm))/sum(cm)
data$precision.model1 <- cm[2,2]/sum(cm[2,])
data$recall.model1 <- cm[2,2]/sum(cm[,2])
#Finally, calculate Kappa for your model according to:
#First generate the table of comparisons
***table1 <- table(data$level.up, data$threshold.pred1)***
#Convert to matrix
matrix1 <- as.matrix(table1)
#Calculate kappa
kappa(matrix1, exact = TRUE)/kappa(matrix1)
#Now choose a different threshold value and repeat these diagnostics. What conclusions can you draw about your two thresholds?