KShape returns a sign-flipped centroid channel on multivariate series
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- numpy, python
- Domain
- machine-learning
Research direction
Start in KShape._shape_extraction and compare the sign check for feature i with the per-channel behavior described in the issue. The reproduction uses a three-channel input and reports each centroid channel’s correlation and inertia. The change is done when all three correlations are 1.0 and inertia is approximately 0.
Written by the indexing model from the issue text.
Description
Describe the bug
In KShape._shape_extraction, the sign check for feature i computes Xp - mu_k and Xp + mu_k over all features of Xp, so the (sz, 1) eigenvector is broadcast across every channel. When channel 0 has the opposite sign to the other channels, the other channels decide the sign and channel 0 of the centroid comes out negated.
To Reproduce
import numpy as np
from tslearn.clustering import KShape
w = np.array([1.0, 2.0, 4.0, 3.0, 1.0, 0.0])
X = np.repeat(np.stack([w, -w, -w], axis=-1)[None], 3, axis=0) # 3 identical series
ks = KShape(n_clusters=1, random_state=0).fit(X)
for ch in range(3):
print(ch, round(np.corrcoef(X[0, :, ch], ks.cluster_centers_[0, :, ch])[0, 1], 3))
print("inertia", ks.inertia_)
Output on main (27e3753):
0 -1.0
1 1.0
2 1.0
inertia 0.4444444444444444
Expected behavior
Every centroid channel has correlation 1.0 with the input and the inertia is 0, since all three series are identical.
Environment (please complete the following information):
- OS: macOS 26.7
- tslearn version: 0.11.0.dev (main at 27e3753), Python 3.11, NumPy 2.4.6
Additional context
#844 compares each eigenvector with its own channel (Xp[:, :, i] against mu_k[:, 0]); with it the output above is 1.0 for all channels and inertia ~0.
- Dominant language
- Python
- Stars
- 3.2k
- Forks
- 418
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 24
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from tslearn-team/tslearn
-
Negative sakoe_chiba_radius is silently accepted: dtw/ctw/frechet return inf and lcss returns 0Possibly taken @MohamedO6 claimed this today. Open
tslearn-team/tslearn#857 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
tslearn-team/tslearn#855 ·
Maintainers usually reply within 1 day
-
PAA / SAX / 1d-SAX silently return NaN or garbage when n_segments is larger than the series lengthPossibly taken @MohamedO6 claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 20/100
tslearn-team/tslearn#852 ·
Maintainers usually reply within 1 day
-
arbitrary code execution when loading a model via from_pickle (CWE-502)Possibly taken @ifaizk5 claimed this 4 days ago. Opendocumentation good first issue
Difficulty 5/5 Over a week Newbie friendliness 25/100
tslearn-team/tslearn#820 · 1 comment ·
Maintainers usually reply within 1 day
-
Time series scalers reject ragged lists despite variable-length supportPossibly taken @sunlishuo25 claimed this 62 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
tslearn-team/tslearn#751 · 1 comment ·
Maintainers usually reply within 1 day
All issues in tslearn-team/tslearn
Similar issues
-
docs(contributing): the two things that silently block a PRPossibly taken A pull request linked to this issue is open or already merged. Openavailable documentation good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 95/100
Nixitov/Riptide-Native#944 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JTHCode/secretguard#24 ·
Maintainers usually reply within 1 day
-
area: middleware documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
good first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 ·
Maintainers usually reply within 1 day