Function for mean shift clustering, which, for a given bandwidth, detects the local modes and performs the clustering.
ms(X, h, subset, thr=0.01, scaled= 1, iter=200, plot=TRUE, ...)
The function ms
produces an object of class ms
,
with components:
a matrix which gives the coordinates of the estimated density modes (i.e., of the mean-shift based cluster centers).
assigns each data point to the cluster center to which its mean shift trajectory has converged.
assigns each data point to the closest cluster center in terms of Euclidean distance.
the data frame (scaled if scaled=TRUE
).
the user-supplied value, could be boolean or numerical.
the data were scaled by dividing each variable through the values provided in this vector.
data matrix or vector.
scalar or vector-valued bandwidth (by default, 5 percent of
the data range, or 20 percent of the standard deviation, respectively, in each direction). If set manually and scaled>0
, this
bandwidth needs to be set on the scaled scale; for instance setting scale; for instance scaled=1
and h=0.10
will use a bandwidth of \(10\) percent of the data range in either direction.
vector specifying a subset of 1:n, where n is the sample size. This allows to run the iterative mean shift procedure only from a subset of points (if unspecified, 1:n is used here, i.e. each data point serves as a starting point).
adjacent mean shift clusters are merged if their relative distance falls below this threshold (see Note section).
if equal to 1 (default), each variable is divided by its range, and if equal to 2 (or any other positive value other than 1), each variable is divided by its standard deviation. If equal to 0, then no scaling is applied.
maximum mean shift iterations (passed to ms.rep
).
if equal to 0, then no plotted output. For bivariate
data, plot=1
gives by default a dynamically created color plot showing the mean
shift trajectories and the resulting clustering.
further graphical parameters.
J. Einbeck. See LPCM-package
for further
acknowledgements.
The methods implemented here can be used for density mode estimation, clustering, and the selection of starting points for the LPC algorithm. They are based on Ameijeiras-Alonso and Einbeck (2023).
It can be shown (Chen, 1995, Comaniciu & Meer, 2002, Li, 2005) that, if the mean shift is computed iteratively, the resulting sequence of local means converges to a mode of the estimated density function. By assigning each data point to the mode to which it has converged, this turns into a clustering technique.
Ameijeiras-Alonso, J. and Einbeck, J. (2023). A fresh look at mean-shift based modal clustering, Advances in Data Analysis and Classification, tools:::Rd_expr_doi("10.1007/s11634-023-00575-1").
Chen, Y. (1995). Mean Shift, Mode Seeking, and Clustering. IEEE Transactions on Pattern Analysis and Machine Intelligence, 17, 790-799.
Comaniciu, D. and Meer,P. (2002). Mean shift: a robust approach toward feature space analysis, IEEE Transactions on Pattern Analysis and Machine Intelligence 24, 603-619.
Li, X, Hu, Z, and Wu, F. (2007). A note on the convergence of the mean shift, Pattern Recognition 40, 1756 - 1762.
ms.rep
, Rc
, plot.ms
data(faithful)
# Mean shift clustering with default bandwidth (5 percent of data range)
ms(faithful)
Run the code above in your browser using DataLab