Mirrors the C# JenksNaturalBreaks class: partitions a one-dimensional sample into
n_clusters classes minimizing the within-class sum of squared deviations.
Value
a list with breaks (each class's maximum value), clusters (an n_clusters by 8
matrix with columns start_index, end_index, count, min, max, sum, average,
variance; the two index columns are 0-based positions into the SORTED data), and gvf,
the goodness-of-variance-fit measure, which approaches 1 for a better fit.
Details
Upstream fails on fully degenerate input: if every value of x is identical, the underlying
algorithm computes a negative class boundary and errors. Any spread at all is fine, including
heavily tied data.
Examples
x <- c(1, 1.2, 1.4, 8, 8.3, 8.6, 30, 31, 32)
ml_jenks_breaks(x, n_clusters = 3)$breaks
#> [1] 1.4 8.6 32.0