def test_fit_transform(params): """Check that fit and transform and fit_transform yield same results.""" transformer = WEASELMUSE(**params) arr_1 = transformer.fit(X, y).transform(X) arr_2 = transformer.fit_transform(X, y) if transformer.sparse: assert (arr_1 != arr_2).nnz == 0 else: np.testing.assert_array_equal(arr_1, arr_2)
def test_n_estimators(): """Check that the number of estimators is the number of features.""" transformer = WEASELMUSE().fit(X, y) assert len(transformer._estimators) == n_features assert len(transformer._estimators_diff) == n_features
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
# License: BSD-3-Clause import numpy as np 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,