딥러닝 모델 설계/R STUDIO
k-means clustering example with R studio and wine data
hellobird
2019. 5. 28. 17:58
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | wine = read.csv("wine.data",header = F) t = " 1) Alcohol 2) Malic acid 3) Ash 4) Alcalinity of ash 5) Magnesium 6) Total phenols 7) Flavanoids 8) Nonflavanoid phenols 9) Proanthocyanins 10)Color intensity 11)Hue 12)OD280/OD315 of diluted wines 13)Proline " s = str_match_all(t, "\\)\\s*(.+)\n") s = sapply(s, function(x){ x[,2] }) s = str_trim(s) s colnames(wine) = c("class", s) str(wine) class = wine[ , 1] x = wine[-1] kc = kmeans(x , 3) kc length(kc$cluster) length(class) colSums(table(class , kc$cluster)) table(wine$class) | cs |