knitr::opts_chunk$set(
    collapse = TRUE,
    comment = "#>",
    fig.path = "README-"
)

CRAN status Codecov test coverage R-CMD-check

tglkmeans - efficient implementation of kmeans++ algorithm

This package provides R binding to a cpp implementation of the kmeans++ algorithm.

Installation

You can install the released version of tglkmeans using the following command:

install.packages("tglkmeans")

Or install the development version using:

if (!require("remotes")) install.packages("remotes")
remotes::install_github("tanaylab/tglkmeans")

Basic usage

library(tglkmeans)

Create 5 clusters normally distributed around 1 to 5, with sd of 0.3:

data <- rbind(
    matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2),
    matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2),
    matrix(rnorm(100, mean = 3, sd = 0.3), ncol = 2),
    matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2),
    matrix(rnorm(100, mean = 5, sd = 0.3), ncol = 2)
)
colnames(data) <- c("x", "y")
head(data)

Cluster using kmeans++:

km <- TGL_kmeans(data, k = 5, id_column = FALSE)
km

Plot the results:

plot(data, col = km$cluster)
points(km$centers, pch = 8, cex = 2)

Vignette

Please refer to the package vignettes for usage and workflow, or look at the usage section in the site.

browseVignettes("usage")

A note regarding random number generation

From version 0.4.0 onward, the package uses R random number generation functions instead of the C++11 random number generation functions. Note that this may result in different results from previous versions. To get the same results as previous versions, set the use_cpp_random argument to TRUE in the TGL_kmeans function.



tanaylab/tglkmeans documentation built on May 16, 2024, 1:05 a.m.