Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into mm/docs2
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewMiddlehurst committed Nov 25, 2024
2 parents 21b23d6 + c835217 commit d6b8076
Show file tree
Hide file tree
Showing 54 changed files with 3,705 additions and 6,242 deletions.
2 changes: 1 addition & 1 deletion aeon/classification/compose/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ClassifierPipeline(BaseCollectionPipeline, BaseClassifier):
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test = load_unit_test(split="test")
>>> pipeline = ClassifierPipeline(
... Resizer(length=10), RocketClassifier(num_kernels=50)
... Resizer(length=10), RocketClassifier(n_kernels=50)
... )
>>> pipeline.fit(X_train, y_train)
ClassifierPipeline(...)
Expand Down
6 changes: 3 additions & 3 deletions aeon/classification/compose/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
make_example_3d_numpy,
make_example_3d_numpy_list,
)
from aeon.testing.mock_estimators import MockCollectionTransformer
from aeon.testing.mock_estimators import MockClassifier, MockCollectionTransformer
from aeon.transformations.collection import (
AutocorrelationFunctionTransformer,
HOG1DTransformer,
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_unequal_tag_inference():
assert not t4.get_tag("capability:unequal_length")

c1 = DummyClassifier()
c2 = RocketClassifier(num_kernels=5)
c2 = MockClassifier()
c3 = RandomForestClassifier(n_estimators=2)

assert c1.get_tag("capability:unequal_length")
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_missing_tag_inference():
assert not t2.get_tag("capability:missing_values")

c1 = DummyClassifier()
c2 = RocketClassifier(num_kernels=5)
c2 = RocketClassifier(n_kernels=5)
c3 = RandomForestClassifier(n_estimators=2)

assert c1.get_tag("capability:missing_values")
Expand Down
20 changes: 10 additions & 10 deletions aeon/classification/convolution_based/_arsenal.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Arsenal(BaseClassifier):
Parameters
----------
num_kernels : int, default=2,000
n_kernels : int, default=2,000
Number of kernels for each ROCKET transform.
n_estimators : int, default=25
Number of estimators to build for the ensemble.
Expand Down Expand Up @@ -114,7 +114,7 @@ class Arsenal(BaseClassifier):
>>> from aeon.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test =load_unit_test(split="test")
>>> clf = Arsenal(num_kernels=100, n_estimators=5)
>>> clf = Arsenal(n_kernels=100, n_estimators=5)
>>> clf.fit(X_train, y_train)
Arsenal(...)
>>> y_pred = clf.predict(X_test)
Expand All @@ -130,7 +130,7 @@ class Arsenal(BaseClassifier):

def __init__(
self,
num_kernels=2000,
n_kernels=2000,
n_estimators=25,
rocket_transform="rocket",
max_dilations_per_kernel=32,
Expand All @@ -141,7 +141,7 @@ def __init__(
n_jobs=1,
random_state=None,
):
self.num_kernels = num_kernels
self.n_kernels = n_kernels
self.n_estimators = n_estimators
self.rocket_transform = rocket_transform
self.max_dilations_per_kernel = max_dilations_per_kernel
Expand Down Expand Up @@ -281,15 +281,15 @@ def _fit_arsenal(self, X, y, keep_transformed_data=False):
train_time = 0

if self.rocket_transform == "rocket":
base_rocket = Rocket(num_kernels=self.num_kernels)
base_rocket = Rocket(n_kernels=self.n_kernels)
elif self.rocket_transform == "minirocket":
base_rocket = MiniRocket(
num_kernels=self.num_kernels,
n_kernels=self.n_kernels,
max_dilations_per_kernel=self.max_dilations_per_kernel,
)
elif self.rocket_transform == "multirocket":
base_rocket = MultiRocket(
num_kernels=self.num_kernels,
n_kernels=self.n_kernels,
max_dilations_per_kernel=self.max_dilations_per_kernel,
n_features_per_kernel=self.n_features_per_kernel,
)
Expand Down Expand Up @@ -419,12 +419,12 @@ def _get_test_params(cls, parameter_set="default"):
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
"""
if parameter_set == "results_comparison":
return {"num_kernels": 20, "n_estimators": 5}
return {"n_kernels": 20, "n_estimators": 5}
elif parameter_set == "contracting":
return {
"time_limit_in_minutes": 5,
"num_kernels": 10,
"n_kernels": 10,
"contract_max_n_estimators": 2,
}
else:
return {"num_kernels": 10, "n_estimators": 2}
return {"n_kernels": 10, "n_estimators": 2}
18 changes: 9 additions & 9 deletions aeon/classification/convolution_based/_minirocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MiniRocketClassifier(BaseClassifier):
Parameters
----------
num_kernels : int, default=10,000
n_kernels : int, default=10,000
The number of kernels for the Rocket transform.
max_dilations_per_kernel : int, default=32
The maximum number of dilations per kernel.
Expand Down Expand Up @@ -71,13 +71,13 @@ class MiniRocketClassifier(BaseClassifier):
Examples
--------
>>> from aeon.classification.convolution_based import RocketClassifier
>>> from aeon.classification.convolution_based import MiniRocketClassifier
>>> from aeon.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test = load_unit_test(split="test")
>>> clf = RocketClassifier(num_kernels=500)
>>> clf = MiniRocketClassifier(n_kernels=500)
>>> clf.fit(X_train, y_train)
RocketClassifier(...)
MiniRocketClassifier(...)
>>> y_pred = clf.predict(X_test)
"""

Expand All @@ -89,14 +89,14 @@ class MiniRocketClassifier(BaseClassifier):

def __init__(
self,
num_kernels=10000,
n_kernels=10000,
max_dilations_per_kernel=32,
estimator=None,
class_weight=None,
n_jobs=1,
random_state=None,
):
self.num_kernels = num_kernels
self.n_kernels = n_kernels
self.max_dilations_per_kernel = max_dilations_per_kernel
self.estimator = estimator

Expand Down Expand Up @@ -129,7 +129,7 @@ def _fit(self, X, y):
self.n_cases_, self.n_channels_, self.n_timepoints_ = X.shape

self._transformer = MiniRocket(
num_kernels=self.num_kernels,
n_kernels=self.n_kernels,
max_dilations_per_kernel=self.max_dilations_per_kernel,
n_jobs=self.n_jobs,
random_state=self.random_state,
Expand Down Expand Up @@ -215,6 +215,6 @@ def _get_test_params(cls, parameter_set="default"):
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
"""
if parameter_set == "results_comparison":
return {"num_kernels": 100}
return {"n_kernels": 100}
else:
return {"num_kernels": 20, "max_dilations_per_kernel": 6}
return {"n_kernels": 20, "max_dilations_per_kernel": 6}
18 changes: 9 additions & 9 deletions aeon/classification/convolution_based/_multirocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MultiRocketClassifier(BaseClassifier):
Parameters
----------
num_kernels : int, default=10,000
n_kernels : int, default=10,000
The number of kernels for the Rocket transform.
max_dilations_per_kernel : int, default=32
The maximum number of dilations per kernel.
Expand Down Expand Up @@ -72,13 +72,13 @@ class MultiRocketClassifier(BaseClassifier):
Examples
--------
>>> from aeon.classification.convolution_based import RocketClassifier
>>> from aeon.classification.convolution_based import MultiRocketClassifier
>>> from aeon.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test = load_unit_test(split="test")
>>> clf = RocketClassifier(num_kernels=500)
>>> clf = MultiRocketClassifier(n_kernels=500)
>>> clf.fit(X_train, y_train)
RocketClassifier(...)
MultiRocketClassifier(...)
>>> y_pred = clf.predict(X_test)
"""

Expand All @@ -90,15 +90,15 @@ class MultiRocketClassifier(BaseClassifier):

def __init__(
self,
num_kernels=10000,
n_kernels=10000,
max_dilations_per_kernel=32,
n_features_per_kernel=4,
estimator=None,
class_weight=None,
n_jobs=1,
random_state=None,
):
self.num_kernels = num_kernels
self.n_kernels = n_kernels
self.max_dilations_per_kernel = max_dilations_per_kernel
self.n_features_per_kernel = n_features_per_kernel
self.estimator = estimator
Expand Down Expand Up @@ -132,7 +132,7 @@ def _fit(self, X, y):
self.n_cases_, self.n_channels_, self.n_timepoints_ = X.shape

self._transformer = MultiRocket(
num_kernels=self.num_kernels,
n_kernels=self.n_kernels,
max_dilations_per_kernel=self.max_dilations_per_kernel,
n_features_per_kernel=self.n_features_per_kernel,
n_jobs=self.n_jobs,
Expand Down Expand Up @@ -219,10 +219,10 @@ def _get_test_params(cls, parameter_set="default"):
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
"""
if parameter_set == "results_comparison":
return {"num_kernels": 100}
return {"n_kernels": 100}
else:
return {
"num_kernels": 200,
"n_kernels": 200,
"max_dilations_per_kernel": 8,
"n_features_per_kernel": 4,
}
35 changes: 17 additions & 18 deletions aeon/classification/convolution_based/_rocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RocketClassifier(BaseClassifier):
Parameters
----------
num_kernels : int, default=10,000
n_kernels : int, default=10,000
The number of kernels for the Rocket transform.
estimator : sklearn compatible classifier or None, default=None
The estimator used. If None, a RidgeClassifierCV(alphas=np.logspace(-3, 3, 10))
Expand Down Expand Up @@ -78,27 +78,28 @@ class RocketClassifier(BaseClassifier):
>>> from aeon.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test = load_unit_test(split="test")
>>> clf = RocketClassifier(num_kernels=500)
>>> clf = RocketClassifier(n_kernels=500)
>>> clf.fit(X_train, y_train)
RocketClassifier(...)
>>> y_pred = clf.predict(X_test)
"""

_tags = {
"capability:multithreading": True,
"capability:multivariate": True,
"capability:multithreading": True,
"algorithm_type": "convolution",
"X_inner_type": "numpy3D",
}

def __init__(
self,
num_kernels=10000,
n_kernels=10000,
estimator=None,
class_weight=None,
n_jobs=1,
random_state=None,
):
self.num_kernels = num_kernels
self.n_kernels = n_kernels
self.estimator = estimator

self.class_weight = class_weight
Expand All @@ -112,8 +113,8 @@ def _fit(self, X, y):
Parameters
----------
X : 3D np.ndarray
The training data of shape = (n_cases, n_channels, n_timepoints).
X : 3D np.ndarray or list
Collection of time series.
y : 3D np.ndarray
The class labels, shape = (n_cases,).
Expand All @@ -127,10 +128,8 @@ def _fit(self, X, y):
Changes state by creating a fitted model that updates attributes
ending in "_" and sets is_fitted flag to True.
"""
self.n_cases_, self.n_channels_, self.n_timepoints_ = X.shape

self._transformer = Rocket(
num_kernels=self.num_kernels,
n_kernels=self.n_kernels,
n_jobs=self.n_jobs,
random_state=self.random_state,
)
Expand Down Expand Up @@ -160,8 +159,8 @@ def _predict(self, X) -> np.ndarray:
Parameters
----------
X : 3D np.ndarray of shape = (n_cases, n_channels, n_timepoints)
The data to make predictions for.
X : 3D np.ndarray or list
Collection of time series.
Returns
-------
Expand All @@ -175,8 +174,8 @@ def _predict_proba(self, X) -> np.ndarray:
Parameters
----------
X : 3D np.ndarray of shape = (n_cases, n_channels, n_timepoints)
The data to make predict probabilities for.
X : 3D np.ndarray or list
Collection of time series.
Returns
-------
Expand All @@ -187,9 +186,9 @@ def _predict_proba(self, X) -> np.ndarray:
if callable(m):
return self.pipeline_.predict_proba(X)
else:
dists = np.zeros((X.shape[0], self.n_classes_))
dists = np.zeros((len(X), self.n_classes_))
preds = self.pipeline_.predict(X)
for i in range(0, X.shape[0]):
for i in range(0, len(X)):
dists[i, np.where(self.classes_ == preds[i])] = 1
return dists

Expand All @@ -215,6 +214,6 @@ def _get_test_params(cls, parameter_set="default"):
`MyClass(**params)` or `MyClass(**params[i])` creates a valid test instance.
"""
if parameter_set == "results_comparison":
return {"num_kernels": 100}
return {"n_kernels": 100}
else:
return {"num_kernels": 20}
return {"n_kernels": 20}
12 changes: 6 additions & 6 deletions aeon/classification/convolution_based/tests/test_arsenal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_contracted_arsenal():
arsenal = Arsenal(
time_limit_in_minutes=0.25,
contract_max_n_estimators=3,
num_kernels=20,
n_kernels=20,
)
arsenal.fit(X_train, y_train)
assert len(arsenal.estimators_) > 1
Expand All @@ -31,13 +31,13 @@ def test_contracted_arsenal():
def test_arsenal():
"""Test correct rocket variant is selected."""
X_train, y_train = make_example_2d_numpy_collection(n_cases=20, n_timepoints=50)
afc = Arsenal(num_kernels=20, n_estimators=2)
afc = Arsenal(n_kernels=20, n_estimators=2)
afc.fit(X_train, y_train)
for i in range(afc.n_estimators):
assert isinstance(afc.estimators_[i].steps[0][1], Rocket)
assert len(afc.estimators_) == 2
afc = Arsenal(
num_kernels=100,
n_kernels=100,
rocket_transform="minirocket",
max_dilations_per_kernel=2,
n_estimators=2,
Expand All @@ -46,7 +46,7 @@ def test_arsenal():
for i in range(afc.n_estimators):
assert isinstance(afc.estimators_[i].steps[0][1], MiniRocket)
afc = Arsenal(
num_kernels=100,
n_kernels=100,
rocket_transform="multirocket",
max_dilations_per_kernel=2,
n_estimators=2,
Expand All @@ -56,7 +56,7 @@ def test_arsenal():
assert isinstance(afc.estimators_[i].steps[0][1], MultiRocket)
X_train, y_train = make_example_3d_numpy(n_cases=20, n_timepoints=50, n_channels=4)
afc = Arsenal(
num_kernels=100,
n_kernels=100,
rocket_transform="minirocket",
max_dilations_per_kernel=2,
n_estimators=2,
Expand All @@ -65,7 +65,7 @@ def test_arsenal():
for i in range(afc.n_estimators):
assert isinstance(afc.estimators_[i].steps[0][1], MiniRocket)
afc = Arsenal(
num_kernels=100,
n_kernels=100,
rocket_transform="multirocket",
max_dilations_per_kernel=2,
n_estimators=2,
Expand Down
Loading

0 comments on commit d6b8076

Please sign in to comment.