This is Jiayu's R Package
License: MIT
For more information please contact jiayuzh@umich.edu
This package includes 6 functions: select_initial_centroids: Selects k random points from data matrix * The initialization step pf k-means cppdist: Caculate the Euclidean distance between two points assign_points: assign points to a cluster * The assignment step pf k-means define_new_centroids: create new centroids based on points clusters * The update step of k-means check_converge: determines if the centroids have reached convergence k_means_cluster: the body function
Using the 'devtools' package:
> install.packages("devtools")
> library(devtools)
> devtools::install_github("silverfoxxxx/package1", build_vignettes = T)
Notice that example datasets and detailed tutorial are in vignettes so please choose build_vignettes = T.
Create a simulated 2-clustered data matrix with 2 columns, and then run k_means_clustering function with default settings:
x = rbind(matrix(rnorm(100, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2))
mydata = x
k = 2
k_means_cluster(mydata, k)
To determine which k to choose, can refer to silhouette in R Documentation help pages.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.