diff --git a/aeon/clustering/feature_based/tests/__init__.py b/aeon/clustering/feature_based/tests/__init__.py new file mode 100644 index 0000000000..3baec9f87b --- /dev/null +++ b/aeon/clustering/feature_based/tests/__init__.py @@ -0,0 +1 @@ +"""Feature Based learning clustering tests.""" \ No newline at end of file diff --git a/aeon/clustering/feature_based/tests/test_catch22.py b/aeon/clustering/feature_based/tests/test_catch22.py new file mode 100644 index 0000000000..6c6a5d1cdb --- /dev/null +++ b/aeon/clustering/feature_based/tests/test_catch22.py @@ -0,0 +1,73 @@ +import numpy as np +from sklearn import metrics + +from aeon.clustering.feature_based import Catch22Clusterer +from aeon.datasets import load_basic_motions, load_gunpoint + +def test_catch22_multivariate(): + """Test Catch22 Clusterer with univariate data.""" + X_train, y_train = load_basic_motions(split="train") + X_test, y_test = load_basic_motions(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + catach22 = Catch22Clusterer( + random_state=1, + + ) + train_result = catach22.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = catach22.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + test_result, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 3, 3, 6, 5, 3, 1, 1, 3], + ) + assert np.array_equal( + train_result, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 7, 2, 4, 3, 3, 6, 1], + ) + assert train_score == 0.6684210526315789 + assert test_score == 0.8263157894736842 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + + +def test_catch22_univariate(): + """Test Catch22 Clusterer with multivariate data.""" + X_train, y_train = load_gunpoint(split="train") + X_test, y_test = load_gunpoint(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + catach22 = Catch22Clusterer( + random_state=1, + ) + train_result = catach22.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = catach22.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + test_result, + [1, 3, 4, 6, 7, 3, 5, 5, 6, 3, 3, 1, 3, 1, 1, 7, 3, 0, 6, 3], + ) + assert np.array_equal( + train_result, + [3, 3, 7, 7, 0, 3, 2, 4, 1, 1, 6, 1, 5, 1, 3, 1, 6, 3, 1, 5], + ) + assert train_score == 0.5947368421052631 + assert test_score == 0.531578947368421 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + + diff --git a/aeon/clustering/feature_based/tests/test_summary.py b/aeon/clustering/feature_based/tests/test_summary.py new file mode 100644 index 0000000000..b69928b47d --- /dev/null +++ b/aeon/clustering/feature_based/tests/test_summary.py @@ -0,0 +1,72 @@ +import numpy as np +from sklearn import metrics + +from aeon.clustering.feature_based import SummaryClusterer +from aeon.datasets import load_basic_motions, load_gunpoint + +def test_summary_univariate(): + """Test Summary Clusterer with univariate data.""" + X_train, y_train = load_gunpoint(split="train") + X_test, y_test = load_gunpoint(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + summary = SummaryClusterer( + random_state=1, + ) + train_result = summary.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = summary.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + test_result, + [2, 0, 4, 2, 6, 0, 1, 7, 3, 0, 6, 2, 0, 2, 2, 6, 0, 6, 2, 6], + ) + assert np.array_equal( + train_result, + [6, 6, 3, 6, 0, 6, 5, 4, 1, 2, 2, 2, 1, 2, 0, 2, 3, 6, 2, 7], + ) + assert train_score == 0.6052631578947368 + assert test_score == 0.5263157894736842 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + + +def test_summary_multivariate(): + """Test Summary Clusterer with multivariate data.""" + X_train, y_train = load_basic_motions(split="train") + X_test, y_test = load_basic_motions(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + summary = SummaryClusterer( + random_state=1, + ) + train_result = summary.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = summary.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + test_result, + [2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 5, 1, 5, 3, 5, 4, 4, 1, 1, 4], + ) + assert np.array_equal( + train_result, + [0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 5, 6, 4, 7, 4, 5, 3, 1], + ) + assert train_score == 0.7421052631578947 + assert test_score == 0.7263157894736842 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + + diff --git a/aeon/clustering/feature_based/tests/test_tsfresh.py b/aeon/clustering/feature_based/tests/test_tsfresh.py new file mode 100644 index 0000000000..630b66f06b --- /dev/null +++ b/aeon/clustering/feature_based/tests/test_tsfresh.py @@ -0,0 +1,75 @@ +import numpy as np +from sklearn import metrics + +from aeon.clustering.feature_based import TSFreshClusterer +from aeon.datasets import load_basic_motions, load_gunpoint + +def test_tsfresh_univariate(): + """Test TSFresh Clusterer with univariate data.""" + X_train, y_train = load_gunpoint(split="train") + X_test, y_test = load_gunpoint(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + tsfresh = TSFreshClusterer( + random_state=1, + n_clusters=2, + ) + train_result = tsfresh.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = tsfresh.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + train_result, + [3, 7, 5, 0, 0, 5, 7, 5, 0, 4, 0, 5, 6, 0, 0, 1, 6, 5, 3, 2], + ) + assert np.array_equal( + test_result, + [3, 3, 0, 5, 0, 4, 6, 7, 0, 3, 5, 5, 0, 6, 0, 5, 0, 5, 0, 7], + + ) + assert train_score == 0.48947368421052634 + assert test_score == 0.5210526315789473 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + + +def test_tsfresh_multivariate(): + """Test TSFresh Clusterer with multivariate data.""" + X_train, y_train = load_basic_motions(split="train") + X_test, y_test = load_basic_motions(split="test") + num_points = 20 + + X_train = X_train[:num_points] + y_train = y_train[:num_points] + X_test = X_test[:num_points] + y_test = y_test[:num_points] + + tsfresh = TSFreshClusterer( + random_state=1, + n_clusters=2, + ) + train_result = tsfresh.fit_predict(X_train) + train_score = metrics.rand_score(y_train, train_result) + test_result = tsfresh.predict(X_test) + test_score = metrics.rand_score(y_test, test_result) + + assert np.array_equal( + train_result, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 3, 4, 6, 7, 2, 5, 5, 3, 1], + ) + assert np.array_equal( + test_result, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 1, 3, 3, 1, 6, 5, 1, 1, 3], + ) + assert train_score == 0.7842105263157895 + assert test_score == 0.8263157894736842 + assert test_result.shape == (20,) + assert train_result.shape == (20,) + +