Estimate an appropriate bandwidth for Mean Shift clustering
bw = estimate_bandwidth(X [, quantile, n_samples, random_state])
is a N x D (N samples, D features) real matrix.
real scalar, optional (default=0.3). Quantile to compute the distance bandwidth. A smaller quantile gives a smaller bandwidth, leading to more clusters. A larger quantile produces a larger bandwidth, leading to fewer clusters.
integer, optional (default=min(500, N)).
Number of samples to randomly select for bandwidth estimation.
If n_samples > size(data,1), all samples are used.
integer, optional (default=-1). Seed for random sampling reproducibility.
real scalar. Estimated bandwidth parameter suitable for Mean Shift clustering. Typically corresponds to a quantile of pairwise distances between points.
estimate_bandwidth computes a bandwidth value from a dataset,
which can be used as the bandwidth parameter in
meanshift.
Note that:
Smaller quantile → smaller bandwidth → more clusters.
Larger quantile → larger bandwidth → fewer clusters.
X = [0 0; 0 1; 1 0; 5 5; 5 6; 6 5; 9 9; 9 10; 10 9]; bw = estimate_bandwidth(X); [centers, labels] = meanshift(X, bw); scf(); scatter(X(:,1), X(:,2), [], labels, "fill"); plot(centers(:,1), centers(:,2), 'r*', "markersize", 10, "thickness", 3); gca().data_bounds = [-1 -1; 11 11]; | ![]() | ![]() |

| Version | Description |
| 2026.0.0 | Function added. |