Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

kms

Kernel mean shift clustering


Description

Kernel mean shift clustering for 2- to 6-dimensional data.

Usage

kms(x, y, H, max.iter=400, tol.iter, tol.clust, min.clust.size, merge=TRUE,
    keep.path=FALSE, verbose=FALSE)

## S3 method for class 'kms'
summary(object, ...)

Arguments

x

matrix of data values

y

matrix of candidate data values for which the mean shift will estimate their cluster labels. If missing, y=x.

H

bandwidth matrix/scalar bandwidth. If missing, Hpi(x,deriv,order=1) is called by default.

max.iter

maximum number of iterations. Default is 400.

tol.iter

distance under which two successive iterations are considered convergent. Default is 0.001*min marginal IQR of x.

tol.clust

distance under which two cluster modes are considered to form one cluster. Default is 0.01*max marginal IQR of x.

min.clust.size

minimum cluster size (cardinality). Default is 0.01*nrow(y).

merge

flag to merge clusters which are smaller than min.clust.size. Default is TRUE.

keep.path

flag to store the density gradient ascent paths. Default is FALSE.

verbose

flag to print out progress information. Default is FALSE.

object

object of class kms

...

other parameters

Details

Mean shift clustering belongs to the class of modal or density-based clustering methods. The mean shift recurrence of the candidate point x is x_j+1 = x_j + H D hat(f)(x_j)/hat(f)(x_j) where j>=0 and x_0 = x. The sequence x_0, x_1, ... follows the density gradient ascent paths to converge to a local mode of the density estimate hat(f). Hence x is iterated until it converges to its local mode, and this determines its cluster label.

The mean shift recurrence is terminated if successive iterations are less than tol.iter or the maximum number of iterations max.iter is reached. Final iterates which are less than tol.clust distance apart are considered to form a single cluster. If merge=TRUE then the clusters whose cardinality is less than min.clust.size are iteratively merged with their nearest cluster.

If the bandwidth H is missing, then the default bandwidth is the plug-in selector for the density gradient Hpi(x,deriv.order=1). Any bandwidth that is suitable for the density gradient is also suitable for the mean shift.

Value

A kernel mean shift clusters set is an object of class kms which is a list with fields:

x,y

data points - same as input

end.points

matrix of final iterates starting from y

H

bandwidth matrix

label

vector of cluster labels

nclust

number of clusters

nclust.table

frequency table of cluster labels

mode

matrix of cluster modes

names

variable names

tol.iter,tol.clust,min.clust.size

tuning parameter values - same as input

path

list of density gradient ascent paths where path[[i]] is the path of y[i,] (only if keep.path=TRUE)

References

Chacon, J.E. & Duong, T. (2013) Data-driven density estimation, with applications to nonparametric clustering and bump hunting. Electronic Journal of Statistics, 7, 499-532.

Comaniciu, D. & Meer, P. (2002). Mean shift: a robust approach toward feature space analysis. IEEE Transactions on Pattern Analysis and Machine Intelligence, 24, 603-619.

See Also

Examples

library(MASS)
data(crabs)
kms.crabs <- kms(x=crabs[,c("FL","CW")])
plot(kms.crabs)
summary(kms.crabs)

kms.crabs <- kms(x=crabs[,c("FL","CW","RW")])
plot(kms.crabs)
plot(kms.crabs, display="plot3D")

ks

Kernel Smoothing

v1.12.0
GPL-2 | GPL-3
Authors
Tarn Duong [aut, cre], Matt Wand [ctb], Jose Chacon [ctb], Artur Gramacki [ctb]
Initial release
2021-02-06

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.