June 2017
Beginner to intermediate
576 pages
15h 22m
English
Run kmeans function using the kcca package to generate five cluster assignments:
# repeat kmeans using the kcca function. Clusters=5 clust1 = kcca(dtMatrix, k = 5, kccaFamily("kmeans")) clust1 > kcca object of family 'kmeans' > > call: > kcca(x = dtMatrix, k = 5, family = kccaFamily("kmeans")) > > cluster sizes: > > 1 2 3 4 5 > 360 120 152 387 8981
Print the number categorized for each cluster:
table(clust1@cluster) > > 1 2 3 4 5 > 360 120 152 387 8981
Merge the clusters with the training data, and show some sample records displaying the cluster assigned to each:
kw_with_cluster2 <- as.data.frame(cbind(OnlineRetail, Cluster = clust1@cluster)) head(kw_with_cluster2) > InvoiceNo StockCode ...