Advertisement
CastelShal

dwdm3

Jul 25th, 2024
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.51 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. library(rattle)
  15. library(rpart)
  16. library(rpart.plot)
  17.  
  18. model = rpart(training_data$Species~., data=training_data, minsplit=2)
  19. fancyRpartPlot(model)
  20.  
  21. prediction = predict(model, testing_data[,-5])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement