Skip to content

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
wants to merge 2 commits into from

Conversation

pk1130
Copy link

@pk1130 pk1130 commented Feb 15, 2021

Reference Issues/PRs

Contributes to issue #19304

What does this implement/fix? Explain your changes.

  • Add poisson as an official criterion to RandomForestRegressor.
  • Change docstring to reflect new addition.
  • Add input validation for poisson criterion.

Any other comments?

Need to expand test suite for addition of poisson criterion to RandomForestRegressor.

Comment on lines -1307 to -1308
.. versionadded:: 0.18
Mean Absolute Error (MAE) criterion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change, i.e. let this versionadded untouched as is.

Comment on lines +319 to +322
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."
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
)
if self.criterion == "poisson":
if np.any(y < 0):
raise ValueError("Some value(s) of y are negative which is"
" not allowed for Poisson regression.")
if np.sum(y) <= 0:
raise ValueError("Sum of y is not positive which is "
"necessary for Poisson regression.")

Copy link
Member

@ogrisel ogrisel Feb 16, 2021

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.

Copy link
Member

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.

@lorentzenchr
Copy link
Member

A next step is to add a test similar (copy&paste) to

# non positive target for Poisson splitting Criterion
est = DecisionTreeRegressor(criterion="poisson")
with pytest.raises(ValueError, match="y is not positive.*Poisson"):
est.fit([[0, 1, 2]], [0, 0, 0])
with pytest.raises(ValueError, match="Some.*y are negative.*Poisson"):
est.fit([[0, 1, 2]], [5, -0.1, 2])

I don't know if we need more tests. It would be nice to always add "poisson" in tests with "criterion". Some of them are not trivial, it starts with poisson requiring y >= 0...
Maybe someone else might give guidance here. (friendly ping at reviewers of #17386 @thomasjpfan @NicolasHug @glemaitre)

@lorentzenchr lorentzenchr linked an issue Feb 15, 2021 that may be closed by this pull request
3 tasks
@lorentzenchr
Copy link
Member

@pk1130 You need to merge main in order to resolve conflicts. It means that the main branch introduced changes, and this PR modifies the same lines of code. Let me know if you need help.

@lorentzenchr
Copy link
Member

@pk1130 Do you need help or, in case you're too busy, could someone else take over?

Co-authored-by: Christian Lorentzen <lorentzen.ch@gmail.com>
@lorentzenchr
Copy link
Member

@pk1130 There are merge conflicts. You need to merge branch main into this branch and resolve the conflicts. This is best done with the support of a good editor/IDE.

@bsun94
Copy link
Contributor

bsun94 commented Apr 7, 2021

hi all, I've opened up a new PR at #19836.

@lorentzenchr
Copy link
Member

#19836 was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants