Skip to content

[ENH] add time series agglomerative clusterer#3553

Merged
TonyBagnall merged 12 commits into
aeon-toolkit:mainfrom
SotonSweetXss:time-series-hc
Jul 9, 2026
Merged

[ENH] add time series agglomerative clusterer#3553
TonyBagnall merged 12 commits into
aeon-toolkit:mainfrom
SotonSweetXss:time-series-hc

Conversation

@SotonSweetXss

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Fixes #3433 . See also #1241

What does this implement/fix? Explain your changes.

A TimeSeriesAgglomerative has been implemented by using aeon to compute a pairwise time series distance matrix (e.g. Euclidean distance, DTW or MSM), and then applying scikit-learn’s AgglomerativeClustering algorithm to this pre-computed distance matrix. It supports single-linkage, complete-linkage and average-linkage clustering, but does not support Ward’s linkage clustering, as this method is incompatible with any pre-computed time series distance.

Does your contribution introduce a new dependency? If yes, which one?

no, Based entirely on sklearn and Aeon

Any other comments?

I will first submit the interface for this level of clustering; if it is approved, I will subsequently add code for reliability verification in aeon\clustering\test.

PR checklist

For all contributions
  • I've added myself to the list of contributors. Alternatively, you can use the @all-contributors bot to do this for you after the PR has been merged.
  • The PR title starts with either [ENH], [MNT], [DOC], [BUG], [REF], [DEP] or [GOV] indicating whether the PR topic is related to enhancement, maintenance, documentation, bugs, refactoring, deprecation or governance.
For new estimators and functions
  • I've added the estimator/function to the online API documentation.
  • (OPTIONAL) I've added myself as a __maintainer__ at the top of relevant files and want to be contacted regarding its maintenance. Unmaintained files may be removed. This is for the full file, and you should not add yourself if you are just making minor changes or do not want to help maintain its contents.
For developers with write access
  • (OPTIONAL) I've updated aeon's CODEOWNERS to receive notifications about future changes to these files.

@aeon-actions-bot aeon-actions-bot Bot added clustering Clustering package enhancement New feature, improvement request or other non-bug code enhancement labels Jun 22, 2026
@aeon-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ enhancement ].
I have added the following labels to this PR based on the changes made: [ clustering ]. Feel free to change these if they do not properly represent the PR.

The Checks tab will show the status of our automated tests. You can click on individual test runs in the tab or "Details" in the panel below to see more information if there is a failure.

If our pre-commit code quality check fails, please run pre-commit locally and push the fixes to your PR branch.

Don't hesitate to ask questions on the aeon Discord channel if you have any.

PR CI actions

These checkboxes will add labels to enable or disable CI functionality for this PR. This may not take effect immediately, and a new commit may be required to run the new configuration.

  • Run pre-commit checks for all files
  • Run mypy typecheck tests
  • Run all pytest tests and configurations
  • Run all notebook example tests
  • Run numba-disabled codecov tests
  • Disable numba cache loading
  • Regenerate expected results for testing
  • Push an empty commit to re-run CI checks

@SotonSweetXss SotonSweetXss marked this pull request as draft June 22, 2026 20:06
@SotonSweetXss

Copy link
Copy Markdown
Contributor Author

Temporarily changed to Draft PR; experimental comparisons are being added gradually

@SotonSweetXss SotonSweetXss changed the title ENH add time series agglomerative clusterer [ENH] add time series agglomerative clusterer Jun 22, 2026
@SotonSweetXss

Copy link
Copy Markdown
Contributor Author

The remaining CI failures appear to be an unrelated and unstable test in test_deep_clusterer_load_model[AEFCNClusterer]. This has occurred in previous PRs; re-running the test resolved the issue.Please ask a user with write permissions to re-run the failed task.

This test file is mainly used to verify the correctness of TimeSeriesAgglomerative when using Euclidean distance.
The tests cover both univariate and multivariate cases. The test data are generated using make_example_3d_numpy provided by aeon. In each case, the single, complete, and average linkage strategies are tested. For every configuration, the output of TimeSeriesAgglomerative(distance="euclidean") is compared with that of scikit-learn's native AgglomerativeClustering(metric="euclidean"). The Adjusted Rand Index (ARI) is used to verify that the two implementations produce equivalent cluster assignments.

In addition, I carried out a simple runtime comparison locally to examine how the runtime changes as the number of samples and the time-series length increase. The experiments also use time-series data generated by aeon. They compare scikit-learn clustering directly with Euclidean distance against TimeSeriesAgglomerative, which first computes an aeon pairwise distance
matrix before performing agglomerative clustering. The figures below show the experimental results.
image
image2

@SotonSweetXss SotonSweetXss marked this pull request as ready for review June 22, 2026 21:42

@TonyBagnall TonyBagnall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this, sorry for the delay.

  1. could you update the init file to include the new clusterer?
  2. we need to resolve how to handle predict is empty. I'll get back to you on that
  3. testing coverage could be improved
  4. _pairwise_distance silently symmetrises the distance matrix
    I would prefer a test and raising an exception, since its quite possible we do get an asymmetric distance and we will need to work out what to do rahter than silently "fixing" it
  5. File name uses camel case, it should just be _agglomorative, location implies clustering
  6. Also add the usual estimator conventions used elsewhere in aeon, such as all, maintainer, and _get_test_params,

@SotonSweetXss

Copy link
Copy Markdown
Contributor Author

This update adds TimeSeriesAgglomerative, a time series agglomerative
clusterer that computes pairwise distances with aeon and then calls sklearn's
AgglomerativeClustering with metric="precomputed".

Main changes:

  • added the new clusterer to aeon.clustering;
  • renamed the implementation file to _agglomerative.py to match aeon naming style;
  • added aeon estimator conventions, including __all__, __maintainer__, and
    _get_test_params;
  • rejected ward linkage because it is not compatible with precomputed distances;
  • replaced silent distance-matrix symmetrisation with explicit validation and error
    handling;
  • added tests for univariate and multivariate time series inputs;
  • added Euclidean sanity checks against sklearn;
  • added tests for invalid linkage, invalid cluster settings, asymmetric distance
    matrices, and non-finite distance matrices.

I kept the tests focused on the aeon wrapper behavior rather than retesting
sklearn's hierarchical clustering implementation.

@SotonSweetXss SotonSweetXss requested a review from TonyBagnall July 8, 2026 12:40
@SotonSweetXss

Copy link
Copy Markdown
Contributor Author

The failing CI checks come from aeon's generic estimator tests calling
predict/predict_proba. TimeSeriesAgglomerative currently raises
NotImplementedError in _predict, since agglomerative clustering is
transductive and sklearn does not provide a native prediction step for unseen
data.

@SotonSweetXss

Copy link
Copy Markdown
Contributor Author

I have added TimeSeriesAgglomerative to the excluded estimator list in testing/testing_config as a short-term fix, since it currently depends on #3613 to pass the generic CI checks, following Tony's suggestion.

@TonyBagnall TonyBagnall merged commit 93b4857 into aeon-toolkit:main Jul 9, 2026
20 checks passed
@SotonSweetXss SotonSweetXss deleted the time-series-hc branch July 9, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clustering Clustering package enhancement New feature, improvement request or other non-bug code enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] Implement Agglomerative clustering algorithm compatible with aeon distances

2 participants