Advertisement
897bhgy

Untitled

Jul 16th, 2023 (edited)
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.80 KB | Source Code | 0 0
  1. # Predict probabilities on testing data
  2. predicted_probabilities <- predict(model2, newdata = test_data, type = "response")
  3.  
  4. # Convert predicted probabilities to binary predictions (1 if P>0.5, else 0)
  5. predicted_classes <- ifelse(predicted_probabilities > 0.5, 1, 0)
  6.  
  7. # Compute confusion matrix for model evaluation
  8. confusion_matrix <- table(Predicted = predicted_classes, Actual = test_data$upgraded)
  9. print(confusion_matrix)
  10.  
  11. # Compute evaluation metrics
  12. accuracy <- sum(predicted_classes == test_data$upgraded) / length(predicted_classes)
  13. precision <- confusion_matrix[2,2] / sum(confusion_matrix[2,])
  14. recall <- confusion_matrix[2,2] / sum(confusion_matrix[,2])
  15.  
  16. # Print evaluation metrics
  17. print(paste("Accuracy: ", accuracy))
  18. print(paste("Precision: ", precision))
  19. print(paste("Recall: ", recall))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement