Add a nearest-centroid (Rocchio) time series classifier. It builds one centroid
per class by averaging the class's training series, then assigns a test series
to the nearest class centroid under a chosen elastic distance.
- Named `NearestCentroidClassifier` to avoid colliding with
`sklearn.neighbors.NearestCentroid` (mirrors `KNeighborsTimeSeriesClassifier`).
- Defaults to `distance="dtw"` with `average_method=None`, which resolves to
DBA (petitjean) for ordinary distances and to the gradient-based soft
barycentre for soft distances. A soft distance and `average_method="soft"`
must be used together; mismatches raise `ValueError`.
- Centroids are computed via `elastic_barycenter_average` (or `mean_average`
for `"mean"`), so the soft-coupling validation is shared with the averaging
module.
- Full numpydoc docstring, tags, `_get_test_params`, unit tests, and an entry
in the classification API reference. Passes the general estimator checks.
Reference Issues/PRs
Fourth and final PR of the soft-distance stack. Stacked on #3526 (soft barycentre averaging) → #3508 → #3483. Please review/merge those first; this branch targets #3526 and the diff shrinks as they merge.
What does this implement/fix?
Adds
NearestCentroidClassifier, a nearest-centroid (Rocchio) time series classifier. It computes one centroid per class by averaging that class's training series, then classifies a new series by the nearest class centroid under a chosen elastic distance.NearestCentroidClassifierto avoid colliding withsklearn.neighbors.NearestCentroid(the same reason aeon's KNN isKNeighborsTimeSeriesClassifier).distance="dtw"andaverage_method=None, which resolves to DBA (petitjean) for ordinary distances and to the gradient-based soft barycentre for soft distances.average_method="soft"; explicitly pairing a soft distance with a non-soft averaging method (or vice versa) raisesValueError. Centroids are computed throughelastic_barycenter_average, so this validation is shared with the averaging module rather than re-implemented._tags,_get_test_params, a runnableExamplesdoctest, and an entry in the classification API reference.Does your contribution introduce a new dependency?
No.
Test plan
test_nearest_centroid.py: per-class centroid shapes, label prediction, the soft auto-promote, the validation matrix (soft+hard and hard+soft both raise), the DBA default, and that mean vs DBA centroids differ on warped data.check_estimator, 22/22) and the doctest.