Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Implemented MockCluster in testing module #2029

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions aeon/clustering/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,43 @@

import numpy as np
import numpy.random
import pytest

from aeon.clustering.base import BaseClusterer
from aeon.testing.mock_estimators import MockCluster


def test_correct_input():
"""Tests errors raised with wrong inputs: X and/or y."""
dummy = MockCluster()

# list of strings X
X = ["list", "of", "invalid", "test", "strings"]
msg1 = r"ERROR passed a list containing <class 'str'>"
with pytest.raises(TypeError, match=msg1):
dummy.fit(X)

# dict X
X = {
0: "invalid",
1: "input",
2: "dict",
}
msg2 = r"ERROR passed input of type <class 'dict'>"
with pytest.raises(TypeError, match=msg2):
dummy.fit(X)

# 2d list of int X
X = [[1, 1, 1], [1, 3, 4]]
msg3 = r"lists should either 2D numpy arrays or pd.DataFrames"
with pytest.raises(TypeError, match=msg3):
dummy.fit(X)

# correct X
X = np.random.randn(5, 5)
dummy.fit(X)
assert (dummy.predict(X)).shape == (5,)
assert (dummy.predict_proba(X)).shape == (5,)


class _TestClusterer(BaseClusterer):
Expand Down
3 changes: 2 additions & 1 deletion aeon/testing/mock_estimators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"MockClassifierPredictProba",
"MockClassifierFullTags",
"MockClassifierMultiTestParams",
"MockCluster",
"MockDeepClusterer",
"MockSegmenter",
"SupervisedMockSegmenter",
Expand All @@ -27,7 +28,7 @@
MockClassifierMultiTestParams,
MockClassifierPredictProba,
)
from aeon.testing.mock_estimators._mock_clusterers import MockDeepClusterer
from aeon.testing.mock_estimators._mock_clusterers import MockCluster, MockDeepClusterer
from aeon.testing.mock_estimators._mock_collection_transformers import (
MockCollectionTransformer,
)
Expand Down
24 changes: 24 additions & 0 deletions aeon/testing/mock_estimators/_mock_clusterers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,32 @@
import numpy as np

from aeon.clustering.base import BaseClusterer
from aeon.clustering.deep_learning.base import BaseDeepClusterer


class MockCluster(BaseClusterer):
"""Mock Cluster for testing base class fit/predict."""

def __init__(self, n_clusters: int = None):
super().__init__(n_clusters)

def _fit(self, X):
"""Mock fit."""
return self

def _predict(self, X):
"""Mock predict."""
return np.zeros(len(X))

def _predict_proba(self, X):
"""Mock predict proba."""
y = np.random.rand(len(X))
return y

def _score(self, X, y):
return np.random.randn(1)


class MockDeepClusterer(BaseDeepClusterer):
"""Mock Deep Clusterer for testing empty base deep class save utilities."""

Expand Down