import matplotlib.pyplot as plt from pyts.datasets import load_basic_motions from pyts.multivariate.transformation import WEASELMUSE from sklearn.preprocessing import LabelEncoder # Toy dataset X_train, _, y_train, _ = load_basic_motions(return_X_y=True) y_train = LabelEncoder().fit_transform(y_train) # WEASEL+MUSE transformation transformer = WEASELMUSE(word_size=2, n_bins=2, window_sizes=[12, 36], chi2_threshold=15, sparse=False) X_weasel = transformer.fit_transform(X_train, y_train) # Visualize the transformation for the first time series plt.figure(figsize=(6, 4)) vocabulary_length = len(transformer.vocabulary_) width = 0.3 plt.bar(np.arange(vocabulary_length) - width / 2, X_weasel[y_train == 0][0], width=width, label='First time series in class 0') plt.bar(np.arange(vocabulary_length) + width / 2, X_weasel[y_train == 1][0], width=width, label='First time series in class 1') plt.xticks(np.arange(vocabulary_length), np.vectorize(transformer.vocabulary_.get)(np.arange(
def test_output_dtype(params, type_desired): """Check that the output dtype is the expected one.""" transformer = WEASELMUSE(**params) output = transformer.fit_transform(X, y) assert isinstance(output, type_desired)
def test_output_ndim(params): """Check that the number of dimensions is always 2.""" transformer = WEASELMUSE(**params) ndim_actual = transformer.fit_transform(X, y).ndim assert ndim_actual == 2