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

[FIX] Fix regressor y value check #53

Merged
merged 7 commits into from
Mar 8, 2021
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Version 0.1.*
.. |Fix| replace:: :raw-html:`<span class="badge badge-danger">Fix</span>` :raw-latex:`{\small\sc [Fix]}`
.. |API| replace:: :raw-html:`<span class="badge badge-warning">API Change</span>` :raw-latex:`{\small\sc [API Change]}`

- |Enhancement| improve target checks for :obj:`CascadeForestRegressor` (`#53 <https://github.com/LAMDA-NJU/Deep-Forest/pull/53>`__) @chendingyan
- |Fix| fix the prediction workflow with only one cascade layer (`#56 <https://github.com/LAMDA-NJU/Deep-Forest/pull/56>`__) @xuyxu
- |Fix| fix inconsistency on predictor name (`#52 <https://github.com/LAMDA-NJU/Deep-Forest/pull/52>`__) @xuyxu
- |Feature| add official support for ManyLinux-aarch64 (`#47 <https://github.com/LAMDA-NJU/Deep-Forest/pull/47>`__) @xuyxu
Expand Down
27 changes: 22 additions & 5 deletions deepforest/cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,20 +1415,37 @@ def __init__(
self.type_of_target_ = None

def _check_target_values(self, y):
"""
Check the input target values for regressor.
"""
"""Check the input target values for regressor."""
self.type_of_target_ = type_of_target(y)

if not self._check_array_numeric(y):
msg = (
"CascadeForestRegressor only accepts numeric values as"
" valid target values."
)
raise ValueError(msg)

if self.type_of_target_ not in (
"continuous",
"continuous-multioutput",
"multiclass",
"multiclass-multioutput",
):
msg = (
"CascadeForestRegressor is used for univariate or multi-variate regression,"
" but the target values seem not to be one of them."
"CascadeForestRegressor is used for univariate or"
" multi-variate regression, but the target values seem not"
" to be one of them."
)
raise ValueError(msg)

def _check_array_numeric(self, y):
"""Check the input numpy array y is all numeric."""
numeric_types = np.typecodes['AllInteger'] + np.typecodes["AllFloat"]
if y.dtype.kind in numeric_types:
return True
else:
return False

def _repr_performance(self, pivot):
msg = "Val MSE = {:.5f}"
return msg.format(pivot)
Expand Down