[BUG] Knn bugfix to allow GridsearchCV and usage with column ensemble.#1903
Merged
TonyBagnall merged 4 commits intomainfrom Jan 21, 2022
Merged
[BUG] Knn bugfix to allow GridsearchCV and usage with column ensemble.#1903TonyBagnall merged 4 commits intomainfrom
TonyBagnall merged 4 commits intomainfrom
Conversation
Collaborator
|
stupid question - what metric do you tune a clustering algorithm for? |
chrisholder
approved these changes
Jan 21, 2022
Collaborator
|
It's a classifier @fkiraly and various distance metrics i.e. some distances are better for certain datasets than others |
Contributor
Author
number of clusters usually, but this is classification, just closing some very old issues |
Collaborator
|
ah, I misread knn for kmeans |
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
Fixes #1713
Fixes #578
Fixes #1057
What does this implement/fix? Explain your changes.
Simple fix to allow for correct parameter setting with GridCV. It removes a temporary measure to allow KNN to pass tests and fixes thanks to the new distance factory. Note we should do some work on making the valid parameters clearer for the different distance measures
Below code all works
code
knn = KNeighborsTimeSeriesClassifier(distance="dtw", n_neighbors=1, distance_params={
"window":0.5})
knn2 = KNeighborsTimeSeriesClassifier(distance="dtw", n_neighbors=1)
param_matrix = {"distance_params": [{"window": x/10.0} for x in range(0,10)]
}
CV Parameter search
grid = GridSearchCV(knn2, param_grid=param_matrix, cv=2, scoring="accuracy")
grid.fit(x_train, y_train)
print(pd.DataFrame(grid.cv_results_))
print(grid)
print(" params after CV = ",knn2.get_params())
knn4 = KNeighborsTimeSeriesClassifier(distance="dtw", n_neighbors=1, distance_params={
"window":0.0})
estimators = [
("knn", knn, [0, 1, 2]),
("knn2", knn2, [3, 4]),
("knn4", knn4, [5]),
]
x_train, y_train = load_basic_motions(split="train")
x_test, y_test = load_basic_motions(split="test")
train column ensemble
col_ens = ColumnEnsembleClassifier(estimators=estimators)
col_ens.fit(x_train, y_train)
print(" Score = ",col_ens.score(x_train, y_train))