Skip to content

Commit 6732112

Browse files
authored
fix(regressor): correctly cap the labels in predict (#1662)
updates pre-commit
1 parent 63bfbeb commit 6732112

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
repos:
55

66
- repo: https://github.com/pycqa/isort
7-
rev: 5.10.1
7+
rev: 5.11.5
88
hooks:
99
- id: isort
1010
name: isort imports autosklearn
@@ -15,7 +15,7 @@ repos:
1515
files: test/.*
1616

1717
- repo: https://github.com/psf/black
18-
rev: 22.10.0
18+
rev: 23.3.0
1919
hooks:
2020
- id: black
2121
name: black formatter autosklearn
@@ -31,15 +31,15 @@ repos:
3131

3232
# This is disabled as most modules fail this
3333
- repo: https://github.com/pycqa/pydocstyle
34-
rev: 6.1.1
34+
rev: 6.3.0
3535
hooks:
3636
- id: pydocstyle
3737
files: DISABLED # autosklearn/.*
3838
always_run: false
3939
additional_dependencies: ["toml"] # Needed to parse pyproject.toml
4040

4141
- repo: https://github.com/pre-commit/mirrors-mypy
42-
rev: v0.990
42+
rev: v1.2.0
4343
hooks:
4444
- id: mypy
4545
name: mypy auto-sklearn

autosklearn/pipeline/regression.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,35 @@ def iterative_fit(self, X, y, n_iter=1, **fit_params):
106106
)
107107

108108
def predict(self, X, batch_size=None):
109+
"""Predict the classes using the selected model.
110+
111+
Predicted values are capped to approximately the maximum and minimum labels
112+
seen during training.
113+
114+
Parameters
115+
----------
116+
X : array-like, shape = (n_samples, n_features)
117+
118+
batch_size: int or None, defaults to None
119+
batch_size controls whether the pipeline will be
120+
called on small chunks of the data. Useful when calling the
121+
predict method on the whole array X results in a MemoryError.
122+
123+
Returns
124+
-------
125+
array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes)
126+
Returns the predicted values"""
109127
y = super().predict(X, batch_size=batch_size)
110-
y[y > (2 * self.y_max_)] = 2 * self.y_max_
128+
129+
if self.y_max_ > 0:
130+
y[y > (2 * self.y_max_)] = 2 * self.y_max_
131+
elif self.y_max_ < 0:
132+
y[y > (0.5 * self.y_max_)] = 0.5 * self.y_max_
111133
if self.y_min_ < 0:
112134
y[y < (2 * self.y_min_)] = 2 * self.y_min_
113135
elif self.y_min_ > 0:
114136
y[y < (0.5 * self.y_min_)] = 0.5 * self.y_min_
137+
115138
return y
116139

117140
def _get_hyperparameter_search_space(

0 commit comments

Comments
 (0)