Advertisement
CastelShal

DWDM2

Jul 25th, 2024
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.50 KB | None | 0 0
  1. data = iris
  2. head(data)
  3.  
  4. sampler = sample(1:nrow(data), size = 0.9*nrow(data), replace = FALSE)
  5. training_data = data[sampler,]
  6. testing_data = data[-sampler,]
  7.  
  8. test_data_label = testing_data[,5]
  9. training_data_label = training_data[,5]
  10.  
  11. test_data = testing_data[-5]
  12. training_data = training_data[,-5]
  13.  
  14. model = naiveBayes(training_data, training_data_label)
  15. prediction = predict(model, test_data)
  16.  
  17. library(caret)
  18.  
  19. table(prediction, test_data_label)
  20. confusionMatrix(prediction, test_data_label)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement