Advertisement
CastelShal

DWDM 3

Aug 1st, 2024
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.74 KB | None | 0 0
  1. #thingey.csv
  2.  
  3. data = read.csv('thingey.csv')
  4. newdata = data[,-1]
  5. newdata = na.omit(newdata)
  6. model = kmeans(newdata, 3)
  7.  
  8. plot(newdata, col=model$cluster)
  9.  
  10. cluster = model$cluster
  11. data = cbind(data, cluster)
  12.  
  13. write.csv(data, "output.csv")
  14.  
  15. #roll no.csv in google classroom
  16. data = read.csv('dataset.csv')
  17. newdata = data[,-1]
  18. newdata = na.omit(newdata)
  19. model = kmeans(newdata, 5)
  20.  
  21. cluster = model$cluster
  22. data = cbind(data, cluster)
  23. write.csv(data, "output.csv")
  24.  
  25.  
  26. #iris dataset
  27. data = iris
  28. newdata = data[,-5]
  29. newdata = na.omit(newdata)
  30. model = kmeans(newdata, 3)
  31. cluster = model$cluster
  32. data = cbind(data, cluster)
  33. clusters = data[6]
  34. plotdata = data[,-c(2,4,5,6)]
  35. plot(plotdata, col=cluster)
  36. #write.csv(copy, "output.csv")
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement