Skip to content

Commit

Permalink
fix(regressor): correctly cap the labels in predict (#1662)
Browse files Browse the repository at this point in the history
updates pre-commit
  • Loading branch information
aron-bram authored Apr 18, 2023
1 parent 63bfbeb commit 6732112
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
repos:

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.11.5
hooks:
- id: isort
name: isort imports autosklearn
Expand All @@ -15,7 +15,7 @@ repos:
files: test/.*

- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.3.0
hooks:
- id: black
name: black formatter autosklearn
Expand All @@ -31,15 +31,15 @@ repos:

# This is disabled as most modules fail this
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
rev: 6.3.0
hooks:
- id: pydocstyle
files: DISABLED # autosklearn/.*
always_run: false
additional_dependencies: ["toml"] # Needed to parse pyproject.toml

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.990
rev: v1.2.0
hooks:
- id: mypy
name: mypy auto-sklearn
Expand Down
25 changes: 24 additions & 1 deletion autosklearn/pipeline/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,35 @@ def iterative_fit(self, X, y, n_iter=1, **fit_params):
)

def predict(self, X, batch_size=None):
"""Predict the classes using the selected model.
Predicted values are capped to approximately the maximum and minimum labels
seen during training.
Parameters
----------
X : array-like, shape = (n_samples, n_features)
batch_size: int or None, defaults to None
batch_size controls whether the pipeline will be
called on small chunks of the data. Useful when calling the
predict method on the whole array X results in a MemoryError.
Returns
-------
array, shape=(n_samples,) if n_classes == 2 else (n_samples, n_classes)
Returns the predicted values"""
y = super().predict(X, batch_size=batch_size)
y[y > (2 * self.y_max_)] = 2 * self.y_max_

if self.y_max_ > 0:
y[y > (2 * self.y_max_)] = 2 * self.y_max_
elif self.y_max_ < 0:
y[y > (0.5 * self.y_max_)] = 0.5 * self.y_max_
if self.y_min_ < 0:
y[y < (2 * self.y_min_)] = 2 * self.y_min_
elif self.y_min_ > 0:
y[y < (0.5 * self.y_min_)] = 0.5 * self.y_min_

return y

def _get_hyperparameter_search_space(
Expand Down

0 comments on commit 6732112

Please sign in to comment.