tslearn-team / tslearn-team/tslearn
KNeighborsTimeSeriesClassifier with DTW slowness
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.2k
- Forks
- 384
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 11
Description
Greetings
As part of testing of different machine learning models I test the KNN model together with DTW and encounter a great slowness in the predictor function of the classifier, I would be very grateful if you could explain to me why there is such a great slowness and how to calibrate the classifier in such a way that it is not slow, attach the code That I run
Thank you
Lior
import numpy as np
from tslearn.generators import random_walk_blobs
from tslearn.neighbors import KNeighborsTimeSeriesClassifier, KNeighborsTimeSeries
import time
np.random.seed(0)
n_ts_per_blob, sz = 20000, 100 #, 1, 1 # , d, n_blobs
X, y = random_walk_blobs(n_ts_per_blob=n_ts_per_blob, sz=sz)
print(y)
print(X.shape)
print(len(y))
start_time = time.time()
knn = KNeighborsTimeSeriesClassifier(n_neighbors=1,metric="dtw",metric_params=dict({"global_constraint":"sakoe_chiba","sakoe_chiba_radius":3}),n_jobs=-1)
end_time = time.time()
print("Creating the Classifier took: {} seconds".format(end_time - start_time))
start_time = time.time()
knn.fit(X,y)
end_time = time.time()
print("FIT function took: {} seconds".format(end_time - start_time))
start_time = time.time()
y_predict = knn.predict(X)
end_time = time.time()
print("Predict function took: {} seconds".format(end_time - start_time))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied Python reproduction with KNeighborsTimeSeriesClassifier, DTW, the Sakoe-Chiba constraint, and n_jobs=-1. Trace the classifier's fit and predict paths to identify the source of the reported prediction slowness; done means explaining the cause and documenting or validating a concrete calibration or change with timing results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100