Skip to content

[MNT] Restructure the distance based clusterers in get_clusterer_by_name - #552

Open
MatthewMiddlehurst wants to merge 8 commits into
time-series-machine-learning:mainfrom
MatthewMiddlehurst:mm/clusterer-getter
Open

MatthewMiddlehurst wants to merge 8 commits into
time-series-machine-learning:mainfrom
MatthewMiddlehurst:mm/clusterer-getter

Conversation

@MatthewMiddlehurst

@MatthewMiddlehurst MatthewMiddlehurst commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Reference Issues/PRs

Follows a review of the estimator getters. The classifier and regressor fixes were in #550.

What does this implement/fix? Explain your changes

Rewrites the distance based clusterers in get_clusterer_by_name in the same format as the classifier and regressor getters.

The old function picked the clusterer with substring tests ("ba" in c, "pam" in c, "som" in c, "clara" after "clarans"), so the result depended on branch order. It parsed a distance from every name and looked up its parameters in _get_distance_default_params. It also read init_algorithm, distance, distance_params and average_params from kwargs before passing kwargs on as well, so setting any of them raised TypeError. kasba, kshape, ksc and the class names printed "No distance metric specified, using default DTW".

Now:

  • Each name in distance_based_clusterers has its own branch, and each branch imports its clusterer.
  • A branch only passes settings which differ from the aeon defaults. These defaults are the same in aeon 1.0 to 1.6. TimeSeriesKMeans adds the averaging distance itself, so average_params only holds the non-default distance settings.
  • kwargs are only passed on. A setting the getter passes raises TypeError on a conflicting keyword, as in the other getters.
  • n_jobs is passed to TimeSeriesKMeans, KSpectralCentroid and KShape, which take it from aeon 1.3 and 1.4. Before, it was only used for the kernel k-means branch, which could not be reached.
  • Only the ERP g, which can depend on the data, still uses a helper (_get_erp_g, the ERP part of _get_distance_default_params). It used to compute g from the default train split loaded from disk, even when the experiment resampled the data or combined the train and test splits. It now resamples with the experiment's seed, and clustering_experiments.py adds the combine flag as a fifth item of data_vars, so g comes from the data the clusterer is fit on.
  • timeserieskernelkmeans is added to the list, so its branch, which could not be reached before, now works. It needs tslearn. The test exclusion for TimeSeriesKernelKMeans is removed.
  • kmeans-ba-lcss, kmeans-ba-erp and kmeans-ssg-ba-erp are removed because they always raised in fit. aeon's barycentre averaging has never supported lcss in aeon 1.x, and erp support was removed in aeon 1.3.0.
  • A name with no branch raises ValueError, and **kwargs is documented.

Compared with main, every remaining name builds the same clusterer type, and fits on MinimalChinatown give the same labels.

Match names exactly like the other getters, instead of using substrings.
The distance is taken from the name once, and kwargs are only passed on.

The clusterers and parameters returned are unchanged. ElasticSOM now
receives kwargs, which were ignored. The "No distance metric specified"
print is removed.
One branch per name in distance_based_clusterers with its settings written
out, as in the other getters, instead of splitting the distance from the
name. Distances without default parameters now leave distance_params as None
rather than {}. Only the data dependent ERP g still uses a helper. Remove the
TimeSeriesKernelKMeans branch, which had no name in the list.
Uses the settings of the branch which could not be reached before.
Remove arguments equal to the aeon defaults, which are the same in aeon 1.0
to 1.6. The averaging distance is added by TimeSeriesKMeans, so
average_params only holds the non-default distance settings. KShape keeps
tol=1e-06, which only became its default in aeon 1.4.
aeon barycentre averaging does not support lcss, and erp support was removed
in aeon 1.3.0, so kmeans-ba-lcss, kmeans-ba-erp and kmeans-ssg-ba-erp always
raised in fit.
Pass n_jobs to TimeSeriesKMeans, KSpectralCentroid and KShape.

The ERP g was found from the default train split. Resample the data when the
experiment does, and include the test data when the train and test splits
are combined, so g comes from the data the clusterer is fit on.
@tsml-actions-bot tsml-actions-bot Bot added experiments Experiments package maintenance Continuous integration, unit testing & package distribution labels Oct 19, 2026
@tsml-actions-bot

Copy link
Copy Markdown
Contributor

Thank you for contributing to tsml-eval

I have added the following labels to this PR based on the title: maintenance.
I have added the following labels to this PR based on the changes made: experiments. 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.

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 all pytest tests and configurations
  • Run all notebook example tests
  • Push an empty commit to re-run CI checks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

experiments Experiments package maintenance Continuous integration, unit testing & package distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant