3
3
__maintainer__ = ["MatthewMiddlehurst" ]
4
4
__all__ = ["DummyRegressor" ]
5
5
6
- import numpy as np
7
6
from sklearn .dummy import DummyRegressor as SklearnDummyRegressor
8
7
9
8
from aeon .regression .base import BaseRegressor
10
9
11
10
12
11
class DummyRegressor (BaseRegressor ):
13
- """
14
- DummyRegressor makes predictions that ignore the input features.
12
+ """Dummy regressor that makes predictions ignoring input features.
15
13
16
- This regressor is a wrapper for the scikit-learn DummyClassifier that serves as a
17
- simple baseline to compare against other more complex regressors.
18
- The specific behaviour of the baseline is selected with the ``strategy`` parameter.
14
+ This regressor serves as a simple baseline to compare against other, more
15
+ complex regressors. It is a wrapper for scikit-learn's DummyRegressor that
16
+ has been adapted for aeon's time series regression framework. The specific
17
+ behavior is controlled by the ``strategy`` parameter.
19
18
20
19
All strategies make predictions that ignore the input feature values passed
21
20
as the ``X`` argument to ``fit`` and ``predict``. The predictions, however,
22
21
typically depend on values observed in the ``y`` parameter passed to ``fit``.
23
22
24
- Function-identical to ``sklearn.dummy.DummyRegressor``, which is called inside.
25
-
26
23
Parameters
27
24
----------
28
25
strategy : {"mean", "median", "quantile", "constant"}, default="mean"
29
- Strategy to use to generate predictions.
30
- * "mean": always predicts the mean of the training set
31
- * "median": always predicts the median of the training set
32
- * "quantile": always predicts a specified quantile of the training set,
33
- provided with the quantile parameter.
34
- * "constant": always predicts a constant value that is provided by
35
- the user.
36
- constant : int or float or array-like of shape (n_outputs,), default=None
37
- The explicit constant as predicted by the "constant" strategy. This
38
- parameter is useful only for the "constant" strategy.
26
+ Strategy to use to generate predictions:
27
+
28
+ - "mean": always predicts the mean of the training set
29
+ - "median": always predicts the median of the training set
30
+ - "quantile": always predicts a specified quantile of the training set,
31
+ provided with the ``quantile`` parameter
32
+ - "constant": always predicts a constant value provided by the user
33
+
34
+ constant : int, float or array-like of shape (n_outputs,), default=None
35
+ The explicit constant value predicted by the "constant" strategy.
36
+ This parameter is only used when ``strategy="constant"``.
37
+
39
38
quantile : float in [0.0, 1.0], default=None
40
- The quantile to predict using the "quantile" strategy. A quantile of
41
- 0.5 corresponds to the median, while 0.0 to the minimum and 1.0 to the
39
+ The quantile to predict when using the "quantile" strategy. A quantile
40
+ of 0.5 corresponds to the median, 0.0 to the minimum, and 1.0 to the
42
41
maximum.
43
42
43
+ Attributes
44
+ ----------
45
+ sklearn_dummy_regressor : sklearn.dummy.DummyRegressor
46
+ The underlying scikit-learn DummyRegressor instance.
47
+
48
+ Notes
49
+ -----
50
+ Function-identical to ``sklearn.dummy.DummyRegressor``, which is called inside.
51
+ This class has been adapted to work with aeon's time series regression framework.
52
+
44
53
Examples
45
54
--------
46
55
>>> from aeon.regression._dummy import DummyRegressor
47
56
>>> from aeon.datasets import load_covid_3month
48
57
>>> X_train, y_train = load_covid_3month(split="train")
49
58
>>> X_test, y_test = load_covid_3month(split="test")
50
59
60
+ Using mean strategy:
61
+
51
62
>>> reg = DummyRegressor(strategy="mean")
52
63
>>> reg.fit(X_train, y_train)
53
64
DummyRegressor()
54
65
>>> reg.predict(X_test)[:5]
55
66
array([0.03689763, 0.03689763, 0.03689763, 0.03689763, 0.03689763])
56
67
68
+ Using quantile strategy:
69
+
57
70
>>> reg = DummyRegressor(strategy="quantile", quantile=0.75)
58
71
>>> reg.fit(X_train, y_train)
59
72
DummyRegressor(quantile=0.75, strategy='quantile')
60
73
>>> reg.predict(X_test)[:5]
61
74
array([0.05559524, 0.05559524, 0.05559524, 0.05559524, 0.05559524])
62
75
76
+ Using constant strategy:
77
+
63
78
>>> reg = DummyRegressor(strategy="constant", constant=0.5)
64
79
>>> reg.fit(X_train, y_train)
65
80
DummyRegressor(constant=0.5, strategy='constant')
66
81
>>> reg.predict(X_test)[:5]
67
82
array([0.5, 0.5, 0.5, 0.5, 0.5])
83
+
68
84
"""
69
85
70
86
_tags = {
@@ -86,29 +102,34 @@ def __init__(self, strategy="mean", constant=None, quantile=None):
86
102
super ().__init__ ()
87
103
88
104
def _fit (self , X , y ):
89
- """Fit the dummy regressor.
105
+ """Fit the dummy regressor to training data .
90
106
91
107
Parameters
92
108
----------
93
- X : 3D np.ndarray of shape [n_cases, n_channels, n_timepoints]
94
- y : array-like, shape = [n_cases] - the target values
109
+ X : np.ndarray of shape (n_cases, n_channels, n_timepoints)
110
+ The training time series data.
111
+ y : array-like of shape (n_cases,)
112
+ The target values for training.
95
113
96
114
Returns
97
115
-------
98
- self : reference to self.
116
+ self : DummyRegressor
117
+ Reference to the fitted regressor.
99
118
"""
100
119
self .sklearn_dummy_regressor .fit (X , y )
101
120
return self
102
121
103
- def _predict (self , X ) -> np . ndarray :
104
- """Perform regression on test vectors X .
122
+ def _predict (self , X ):
123
+ """Make predictions on test data .
105
124
106
125
Parameters
107
126
----------
108
- X : 3D np.ndarray of shape [n_cases, n_channels, n_timepoints]
127
+ X : np.ndarray of shape (n_cases, n_channels, n_timepoints)
128
+ The test time series data.
109
129
110
130
Returns
111
131
-------
112
- y : predictions of target values for X, np.ndarray
132
+ y_pred : np.ndarray of shape (n_cases,)
133
+ Predicted target values for X.
113
134
"""
114
135
return self .sklearn_dummy_regressor .predict (X )
0 commit comments