Closed
Description
Description
AdaBoostClassifier
throws a ZeroDivisionError
when calling predict_proba
if the classifier has only been fit on samples from a single class.
Steps/Code to Reproduce
import sklearn.ensemble
import numpy as np
X = np.random.random((10, 10))
y = np.zeros((10, ))
ada = sklearn.ensemble.AdaBoostClassifier().fit(X, y)
ada.predict(X)
ada.predict_proba(X)
Expected Results
A ValueError
when using fit
.
Actual Results
In [10]: ada.predict_proba(X)
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-10-492c02a5f340> in <module>()
----> 1 ada.predict_proba(X)
/home/feurerm/virtualenvs/2016_epm/lib/python3.4/site-packages/sklearn/ensemble/weight_boosting.py in predict_proba(self, X)
765
766 proba /= self.estimator_weights_.sum()
--> 767 proba = np.exp((1. / (n_classes - 1)) * proba)
768 normalizer = proba.sum(axis=1)[:, np.newaxis]
769 normalizer[normalizer == 0.0] = 1.0
ZeroDivisionError: float division by zero
Versions
- Linux-3.13.0-54-generic-x86_64-with-Ubuntu-14.04-trusty
- Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] - NumPy 1.11.1
- SciPy 0.18.0
- Scikit-Learn 0.17.1