Espadan

Untitled

Mar 31st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.55 KB | None | 0 0
  1. setwd("C:\\Users\\Nikita\\Downloads\\r_lab3")
  2. x <- read.csv(file="clustering_group_10.csv", header = FALSE)
  3. plot(x, type="p", col="red")
  4.  
  5. #алгоритм k-means
  6. kmeans.model = kmeans(x, 2, iter.max = 100, nstart = 1, algorithm = "Lloyd")
  7. #Нахождение модели
  8. kmeans.model$tot.withinss
  9. kmeans.model$centers
  10. #Распечатка результатов
  11. for (i in 1:1000){
  12.   y1<-x[i,1]
  13.   y2<-x[i,2]
  14.   if (kmeans.model$cluster[i]==1)
  15.     points(y1,y2,col="blue", type="p")
  16.   else
  17.     points(y1,y2,col="red", type="p")
  18. }
Advertisement
Add Comment
Please, Sign In to add comment