Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[MRG+1] FIX AdaBoost ZeroDivisionError in proba #7501 #8371

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

Merged
merged 7 commits into from
Feb 20, 2017

Conversation

dokato
Copy link
Contributor

@dokato dokato commented Feb 16, 2017

Reference Issue

What does this implement/fix? Explain your changes.

Fixes #7501. As suggested returns vector of ones when only one class.

Any other comments?

Tests added as well.

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

The Travis error looks genuine and happens on the test you have added. There are flake8 errors as well that you need to fix.

@dokato
Copy link
Contributor Author

dokato commented Feb 16, 2017

Ok, done. Sorry for double commit. I've pushed not finished amendments by mistake.

@lesteve
Copy link
Member

lesteve commented Feb 16, 2017

It looks like github does not recognise your email. You probably need to have the same email for your git settings and for github. This makes it easier to track who changes what.

@codecov
Copy link

codecov bot commented Feb 16, 2017

Codecov Report

Merging #8371 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #8371      +/-   ##
==========================================
+ Coverage   94.75%   94.75%   +<.01%     
==========================================
  Files         342      342              
  Lines       60801    60807       +6     
==========================================
+ Hits        57609    57615       +6     
  Misses       3192     3192
Impacted Files Coverage Δ
sklearn/ensemble/tests/test_weight_boosting.py 100% <100%> (ø)
sklearn/ensemble/weight_boosting.py 96.49% <100%> (+0.02%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80c1bf1...ad9227a. Read the comment docs.

@dokato dokato force-pushed the adaboost_zerodiverror branch from e42d3ef to 9a386a2 Compare February 16, 2017 13:01
normalizer[normalizer == 0.0] = 1.0
proba /= normalizer

if n_classes > 1:
Copy link
Member

Choose a reason for hiding this comment

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

I think you should move the n_classes == 1 sooner to avoid to do non meaningful computation, e.g. something like:

...
X = self._validate_X_predict(X)
if n_classes == 1:
    return np.ones((X.shape[0], 1))
... # the rest of the code can stay exactly the same without an else clause

@@ -74,6 +74,13 @@ def predict_proba(self, X):
assert_array_equal(np.argmax(samme_proba, axis=1), [0, 1, 1, 1])


def test_oneclass_proba():
# Test `predict_proba` robustness for one class label input.
y_t = np.ones((len(X),))
Copy link
Member

Choose a reason for hiding this comment

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

y_t = np.ones(len(X)) is the same and easier to read.

@@ -74,6 +74,13 @@ def predict_proba(self, X):
assert_array_equal(np.argmax(samme_proba, axis=1), [0, 1, 1, 1])


def test_oneclass_proba():
# Test `predict_proba` robustness for one class label input.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a reference to the original issue i.e. https://github.com/scikit-learn/scikit-learn/issues/7501.

Nitpick: I don't think the backquotes around predict_proba are really useful.

@@ -74,6 +74,13 @@ def predict_proba(self, X):
assert_array_equal(np.argmax(samme_proba, axis=1), [0, 1, 1, 1])


def test_oneclass_proba():
Copy link
Member

Choose a reason for hiding this comment

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

put adaboost somewhere in the test function.

Copy link
Member

@lesteve lesteve left a comment

Choose a reason for hiding this comment

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

Besides the minor comment LGTM.

You probably want to add an entry in doc/whats_new.rst as well.

@@ -770,7 +773,6 @@ def predict_proba(self, X):
normalizer = proba.sum(axis=1)[:, np.newaxis]
normalizer[normalizer == 0.0] = 1.0
proba /= normalizer

Copy link
Member

Choose a reason for hiding this comment

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

Good practice: do not change code if there is not a good reason to. In this case can you please put the newline where it was?

@lesteve lesteve changed the title FIX AdaBoost ZeroDivisionError in proba #7501 [MRG+1] FIX AdaBoost ZeroDivisionError in proba #7501 Feb 16, 2017
@lesteve
Copy link
Member

lesteve commented Feb 20, 2017

@dokato can you tackle #8371 (comment) and add an entry in doc/whats_new.rst?

@dokato
Copy link
Contributor Author

dokato commented Feb 20, 2017

@lesteve Yes, I did it, but I'm struggling with strange problem. I've pushed my change, but it's not visible at github. When I make git diff adaboost_zerodiverror origin/adaboost_zerodiverror there is no difference however. Plus I cloned my fork to different folder again, changed to appropriate branch and my commit is there in logs! Never have I seen something like this before, have you?

@lesteve
Copy link
Member

lesteve commented Feb 20, 2017

Plus I cloned my fork to different folder again, changed to appropriate branch and my commit is there in logs! Never have I seen something like this before, have you?

I have seen problems like this when github were having operational issues, but that does not seem to be the case at the moment. I just pushed in my fork master branch and I could see the update right away.

Maybe try to git commit --amend + git push -f to see whether that was a one-off glitch. Also double-check that you have not missed something, which happens to the best of us sometimes ;-).

@dokato dokato force-pushed the adaboost_zerodiverror branch from 2cb2529 to fc337c5 Compare February 20, 2017 09:59
@codecov-io
Copy link

codecov-io commented Feb 20, 2017

Codecov Report

Merging #8371 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #8371      +/-   ##
==========================================
+ Coverage   94.75%   94.75%   +<.01%     
==========================================
  Files         342      342              
  Lines       60813    60819       +6     
==========================================
+ Hits        57621    57627       +6     
  Misses       3192     3192
Impacted Files Coverage Δ
sklearn/ensemble/weight_boosting.py 96.49% <100%> (+0.02%)
sklearn/ensemble/tests/test_weight_boosting.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 41200e1...0deb2a3. Read the comment docs.

@dokato
Copy link
Contributor Author

dokato commented Feb 20, 2017

Amending and pushing again helped, thanks for suggestion!

@@ -153,11 +153,14 @@ Enhancements
Bug fixes
.........

- Fixed a bug where :class:`sklearn.ensemble.AdaBoostClassifier` throws
``ZeroDivisionError`` while fitting data with single class labels.
Copy link
Member

Choose a reason for hiding this comment

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

Beware this is a rst file, rst and markdown do not have the same syntax. I changed the single back-quotes in double back-quotes.

@lesteve
Copy link
Member

lesteve commented Feb 20, 2017

LGTM, I'll merge when the CIs are green. Ping me if I forget.

@dokato
Copy link
Contributor Author

dokato commented Feb 20, 2017

@lesteve just to remind you to merge.

@jnothman jnothman merged commit fb65a0a into scikit-learn:master Feb 20, 2017
@lesteve
Copy link
Member

lesteve commented Feb 21, 2017

Thanks a lot @dokato for the PR and thanks @jnothman for merging this one.

sergeyf pushed a commit to sergeyf/scikit-learn that referenced this pull request Feb 28, 2017
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

* Tweak in rst
@Przemo10 Przemo10 mentioned this pull request Mar 17, 2017
Sundrique pushed a commit to Sundrique/scikit-learn that referenced this pull request Jun 14, 2017
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

* Tweak in rst
NelleV pushed a commit to NelleV/scikit-learn that referenced this pull request Aug 11, 2017
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

* Tweak in rst
paulha pushed a commit to paulha/scikit-learn that referenced this pull request Aug 19, 2017
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

* Tweak in rst
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

* Tweak in rst
lemonlaug pushed a commit to lemonlaug/scikit-learn that referenced this pull request Jan 6, 2021
…ikit-learn#8371)

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX AdaBoost ZeroDivisionError in proba scikit-learn#7501 - tests corrected

* FIX scikit-learn#7501 improvements suggested by lesteve introduced

* FIX scikit-learn#7501 whats_new file updated

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

Successfully merging this pull request may close these issues.

AdaBoost ZeroDivisionError
4 participants