Skip to content

[BUG] tslearn warpper bug when save_transformed_data is True #3380

@TonyBagnall

Description

@TonyBagnall

Describe the bug

In fit, when save_transformed_data=True, we save X_t into self.transformed_data, but X_t is just the tslearn-formatted input, not the shapelet transform.

Then get_transform(X) ignores its X argument and returns self.transformed_data_, and get_locations(X) ignores its X argument and calls self.clf_.locate(self.transformed_data_). So we are not actually saving the transform, and we are not actually using the X passed to those methods.

this is an addition to #3379 where it crashes with version 0.8.0

Steps/Code to reproduce the bug

import numpy as np

from aeon.classification.shapelet_based import LearningShapeletClassifier
from aeon.testing.data_generation import make_example_3d_numpy

X_train = make_example_3d_numpy(
    n_cases=10, n_channels=1, n_timepoints=20, random_state=0, return_y=False
)
X_test = make_example_3d_numpy(
    n_cases=3, n_channels=1, n_timepoints=20, random_state=1, return_y=False
)
y_train = np.array([0, 1] * 5)

clf = LearningShapeletClassifier(
    max_iter=10, total_lengths=1, save_transformed_data=True, random_state=0
)
clf.fit(X_train, y_train)

# Bug 1: get_transform(X) ignores X and returns cached training data
Xt_test = clf.get_transform(X_test)
assert np.array_equal(Xt_test, clf.transformed_data_)

# Bug 2: returned object has training-set case count, not test-set case count
assert Xt_test.shape[0] == X_train.shape[0]
assert Xt_test.shape[0] != X_test.shape[0]

# Bug 3: get_locations(X) ignores X as well
loc_train = clf.get_locations(X_train)
loc_test = clf.get_locations(X_test)
assert np.array_equal(loc_train, loc_test)

Expected results

save transform not X

Actual results

saves X not transform

Versions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingclassificationClassification package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions