Fix predict method for multiclass multioutput ensemble models#12834
Merged
jnothman merged 4 commits intoscikit-learn:masterfrom Jan 2, 2019
Merged
Fix predict method for multiclass multioutput ensemble models#12834jnothman merged 4 commits intoscikit-learn:masterfrom
jnothman merged 4 commits intoscikit-learn:masterfrom
Conversation
adrinjalali
reviewed
Dec 20, 2018
sklearn/ensemble/forest.py
Outdated
| n_samples = proba[0].shape[0] | ||
| predictions = np.zeros((n_samples, self.n_outputs_)) | ||
| predictions = np.empty((n_samples, self.n_outputs_), | ||
| dtype='object') |
Member
There was a problem hiding this comment.
wouldn't it be better to have dtype=self.classes_.dtype or something?
jnothman
reviewed
Dec 20, 2018
|
|
||
| with np.errstate(divide="ignore"): | ||
| proba = est.predict_proba(X_test) | ||
| assert_equal(len(proba), 2) |
Member
There was a problem hiding this comment.
With the adoption of pytest, we are phasing out use of test helpers assert_equal, assert_true, etc. Please use bare assert statements, e.g. assert x == y, assert not x, etc.
Contributor
Author
|
Sorry for the delay! I committed a couple of changes to address the code review comments. |
jnothman
approved these changes
Jan 2, 2019
Member
jnothman
left a comment
There was a problem hiding this comment.
LGTM!
Please add an entry to the change log at doc/whats_new/v0.21.rst. Like the other entries there, please reference this pull request with :issue: and credit yourself (and other contributors if applicable) with :user:
rth
pushed a commit
to rth/scikit-learn
that referenced
this pull request
Jan 3, 2019
adrinjalali
pushed a commit
to adrinjalali/scikit-learn
that referenced
this pull request
Jan 7, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
xhluca
pushed a commit
to xhluca/scikit-learn
that referenced
this pull request
Apr 28, 2019
koenvandevelde
pushed a commit
to koenvandevelde/scikit-learn
that referenced
this pull request
Jul 12, 2019
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reference Issues/PRs
Fixes #12831.
What does this implement/fix? Explain your changes.
This PR fixes a bug where the
predictmethod would fail for multiclass multioutput ensemble models, if any of the dependent variables were strings. The underlying issue was preallocating thepredictoutput usingnp.zeros, which would then error when string predictions were inserted. I replaced the function call with a more dtype-agnostic call tonp.empty.Any other comments?