aeon icon indicating copy to clipboard operation
aeon copied to clipboard

[ENH]Use n_jobs parameter in KNeighborsTimeSeriesClassifier.

Open steenrotsman opened this issue 8 months ago • 3 comments

Reference Issues/PRs

Fixes #2478. See also #2545 and #2578.

What does this implement/fix? Explain your changes.

Uses n_jobs parameter in _predict and predict_proba of KNeighborsTimeSeriesClassifier. Parallelization is done in these methods instead of _kneighbors to potentially allow speedup through upper bounding the distance.

PR checklist

For all contributions
  • [x] 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.
  • [x] 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.

steenrotsman avatar Mar 24 '25 10:03 steenrotsman

Thank you for contributing to aeon

I have added the following labels to this PR based on the title: [ $\color{#FEF1BE}{\textsf{enhancement}}$ ]. I have added the following labels to this PR based on the changes made: [ $\color{#BCAE15}{\textsf{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, any trivial fixes will automatically be pushed to your PR unless it is a draft.

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

PR CI actions

These checkboxes will add labels to enable/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
  • [ ] Stop automatic pre-commit fixes (always disabled for drafts)
  • [ ] Disable numba cache loading
  • [ ] Push an empty commit to re-run CI checks

aeon-actions-bot[bot] avatar Mar 24 '25 10:03 aeon-actions-bot[bot]

In #2478, I've put some benchmarks. These are the entries on three data sets with 1 or 8 cores with only Aeon's builtin DTW:

name avg std min
ACSF1 (1) 110.2201 2.4291 107.7615
ACSF1 (8) 49.2053 1.0859 48.3538
ArrowHead (1) 1.8508 0.0506 1.7939
ArrowHead (8) 0.5634 0.0114 0.5545
GunPoint (1) 0.8112 0.0238 0.7918
GunPoint (8) 1.0206 1.6650 0.2700

For the small GunPoint data set, overhead is larger than gains from parallelization. I expect that for ED, data sets would need to be larger to get a performance increase (if that's even possible) compared to DTW.

Equivalence is tested in aeon/distances/tests/test_sklearn_compatibility.py: previous version tested equivalence with sklearn. The test passes with the new version, so the new output is equal to the old output.

steenrotsman avatar Mar 27 '25 15:03 steenrotsman

LGTM. Question is still open on whether this is the best way to do this for KNN, but it is much better than nothing.

MatthewMiddlehurst avatar Apr 30 '25 12:04 MatthewMiddlehurst