Skip to content

[ENH] Add prior_correction to HIVECOTEV2, default 0.5 - #3992

Open
TonyBagnall wants to merge 2 commits into
mainfrom
hc2-prior-correction
Open

TonyBagnall wants to merge 2 commits into
mainfrom
hc2-prior-correction

Conversation

@TonyBagnall

@TonyBagnall TonyBagnall commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

edit: deprecated code in HC2 and increased coverage while I was here

we noted in the HC2 paper that it does relatively poorly on imbalanced data. It turns out a simple correction in the ensemble stage goes a long way to correct this. tl;dr: accuracy goes up a little (average up 0.17 on UCR and 0.48 on multiverse) balacc a lot (0.74 on UCR, 2.44 on Multiverse!)

This PR adds prior_correction parameter to HIVECOTEV2, default 0.5.

HIVE-COTE 2's CAWPE combination leans towards the classes that are common in the training data: when the components are unsure, the weighted sum favours the majority class, and the rarer classes are under-predicted. The correction divides the combined probabilities by the train class prior raised to prior_correction and renormalises, before the argmax.

  • 0 gives the original HC2 combination; 1 corrects fully to a uniform class prior (i.e. balanced accuracy).
  • With balanced training classes, the prior is uniform and nothing changes.
  • It acts on the combined probabilities only, so nothing is refitted, and it can be changed on a fitted model.

Changes:

  • _BaseHIVECOTE gets prior_correction (default 0, so HIVECOTEV1 is unchanged), stores the train class proportions as class_prior_, and combines the components in a new _combine method.
  • HIVECOTEV2.predict_proba_with_components uses _combine, so it returns the same probabilities as predict_proba.
  • HIVECOTEV2 defaults to prior_correction=0.5.

Results. HC2 was rebuilt from the component results files with each beta.

UCR, 112 univariate datasets, 30 resamples. Changes are in percentage points against beta = 0; p is from a Wilcoxon signed-rank test over datasets.

beta accuracy % change p balanced accuracy % change p
0 (current) 89.301 87.245
0.25 89.429 +0.128 0.0001 87.640 +0.395 <0.0001
0.5 89.469 +0.168 0.002 87.982 +0.737 <0.0001
0.75 89.341 +0.040 0.045 88.227 +0.982 <0.0001
1.0 88.991 −0.310 0.18 88.380 +1.135 <0.0001

At beta = 0.5, the change by train imbalance (largest class over smallest), as accuracy / balanced accuracy:

train imbalance datasets change
below 1.1 49 +0.01 / +0.01
1.1 to 2 27 +0.19 / +0.40
2 or more 36 +0.37 / +1.99
5 or more 13 +0.23 / +3.58

Two further archives that were not used to choose 0.5:

archive change in accuracy change in balanced accuracy
Multivariate, 66 datasets, resample 0, HC2 without TDE (no TDE train files were available) +0.48 (p = 0.05) +2.33 (p < 0.0001)
EEG, 51 datasets, resample 0 +0.31 +0.96 (p = 0.004)

0.5 has the highest accuracy of the values tried and about two thirds of the balanced accuracy gain of full correction. Larger values start to lose accuracy on highly imbalanced data.

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

No.

Any other comments?

  • This changes the default output of HIVECOTEV2 on imbalanced training data: predict_proba changes, and some predict results change. prior_correction=0 restores the old behaviour. Should this go through a deprecation cycle (default 0 with a warning, then 0.5), or is a changed default acceptable for a minor release?
  • The expected-results check for HIVECOTEV2 is already excluded in testing_config.py, so no stored results needed regenerating.
  • New tests check that the correction matches the formula through both predict_proba and predict_proba_with_components, that balanced data is unchanged, and that negative values are rejected. check_estimator passes for HIVECOTEV1 and HIVECOTEV2.

The CAWPE combination leans towards classes that are common in the training
data. HIVECOTEV2 now divides the combined probabilities by the train class
prior raised to prior_correction and renormalises. 0 gives the original
combination; the base class defaults to 0, so HIVECOTEV1 is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aeon-actions-bot aeon-actions-bot Bot added classification Classification package enhancement New feature, improvement request or other non-bug code enhancement labels Nov 8, 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: classification. 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

TonyBagnall added a commit to time-series-machine-learning/tsml-eval that referenced this pull request Nov 8, 2026
…the HC2 builder

HC2 builds its DrCIF with 500 trees, but the EEG components ran the default
200, so HC2 from file now uses DrCIF-500; DrCIF stays as a standalone entry.
--prior-correction applies the beta of aeon-toolkit/aeon#3992 when building.
@TonyBagnall
TonyBagnall marked this pull request as ready for review November 8, 2026 16:33

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

classification Classification 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.

1 participant