Repository navigation
[BUG] Fix clustering experiments for clusterers that cannot predict new cases - #553
Open
MatthewMiddlehurst wants to merge 4 commits into
Conversation
Contributor
Thank you for contributing to
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
Resolves the todo in
test_clustering.pyto add DBSCAN back to the tests.What does this implement/fix? Explain your changes
run_clustering_experimentfails for scikit-learn clusterers that cannot predict new cases, such asDBSCAN, even for train-only runs. It raisesAttributeError: 'DBSCAN' object has no attribute 'predict'.can_predictwas only worked out for aeon clusterers. For wrapped scikit-learn clusterers it stayedTrue, so the train results calledpredict_proba, which reachedDBSCAN.predict. The test fold never checkedcan_predict, soTimeSeriesAgglomerativealso failed whenever a test file was requested.SklearnToAeonClusterersets aeon'scapability:predicttag from whether the wrapped clusterer haspredict. scikit-learn has no tag for this; method availability is how it declares it (available_ifmakeshasattrFalse). This also applies to OPTICS, HDBSCAN, AgglomerativeClustering and SpectralClustering.run_clustering_experimentreads that tag right after wrapping, so wrapped scikit-learn clusterers uselabels_for train results, as aeon clusterers that cannot predict already do. TheTimeSeriesAgglomerativeclass-name workaround stays, as aeon 1.6.0 does not set its tag.ValueErrorbefore fitting. Skipping the test file instead would make_check_existing_resultsrerun the experiment every time, as the file never appears.Other fixes to
SklearnToAeonClustererfound while testing:labels_andpredictare mapped to one cluster after the others. scikit-learn clusterers such as DBSCAN, OPTICS, HDBSCAN andMeanShift(cluster_all=False)label noise-1, which aeon and tsml clusterers do not use. Before,-1fromlabels_was written to file as the prediction while its probability went to the last column through negative indexing.-1frompredict(for exampleBirchwith DBSCAN as its final clustering step) went through aeon's default_predict_proba, which renumbers predictions in place; a negative label made every cluster collapse into one. Relabelling noise raises a warning with the number of cases and the cluster they go to. Ifpredictlabels noise but no training cases were noise, there is no noise cluster to use, so it raises aValueError.n_clustersis only copied from the wrapped clusterer when it is an integer, otherwise it is the number of clusters inlabels_.Birchalso acceptsNoneor a clusterer. A clusterer raisedTypeErrorinpredict_proba, andNonemade aeon size the probabilities per call, so train and test files had different cluster counts (13 and 8 in one run).Tests: DBSCAN is back in
test_n_clusters,test_transductive_clustererruns for DBSCAN too and checks that the written predictions match the probabilities, a new test checks the test-file error for both clusterers, and new wrapper tests cover the tag, noise fromlabels_andpredictwith its warnings, noise inpredictwithout training noise, and non-integern_clusters.