-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
ENH Add Poisson criterion to RandomForestRegressor #19464
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -315,6 +315,12 @@ def fit(self, X, y, sample_weight=None): | |
# Remap output | ||
self.n_features_ = X.shape[1] | ||
|
||
# add input validation for poisson criterion | ||
if (self.criterion == "poisson" and np.any(y < 0)): | ||
raise ValueError("Some value(s) of y are negative which is" | ||
" not allowed for Poisson regression." | ||
) | ||
|
||
y = np.atleast_1d(y) | ||
if y.ndim == 2 and y.shape[1] == 1: | ||
warn("A column-vector y was passed when a 1d array was" | ||
|
@@ -1298,14 +1304,16 @@ class RandomForestRegressor(ForestRegressor): | |
The default value of ``n_estimators`` changed from 10 to 100 | ||
in 0.22. | ||
|
||
criterion : {"mse", "mae"}, default="mse" | ||
criterion : {"mse", "mae", "poisson"}, default="mse" | ||
The function to measure the quality of a split. Supported criteria | ||
are "mse" for the mean squared error, which is equal to variance | ||
reduction as feature selection criterion, and "mae" for the mean | ||
absolute error. | ||
reduction as feature selection criterion, "mae" for the mean | ||
absolute error, and "poisson" which uses reduction in | ||
Poisson deviance to find splits. | ||
|
||
.. versionadded:: 0.18 | ||
Mean Absolute Error (MAE) criterion. | ||
Comment on lines
-1307
to
-1308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this change, i.e. let this |
||
|
||
.. versionadded:: 1.0 | ||
Added criterion "poisson". | ||
|
||
max_depth : int, default=None | ||
The maximum depth of the tree. If None, then nodes are expanded until | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the later error message would make more sense if we emphasized that the sum of y needs to be strictly positive. Alternatively we can could say that
y
cannot be uniformly zero.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointing out strict positiveness is good. Note that the above is the exact same error message as in the tree module. If we improve it here, the same change should be applied there.