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

Skip to content

Commit 4064301

Browse files
pprettlarsmans
authored andcommitted
raise ValueError if division through zero in LogOddsEstimator
1 parent 2da9f01 commit 4064301

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sklearn/ensemble/gradient_boosting.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ class LogOddsEstimator(BaseEstimator):
7777
"""An estimator predicting the log odds ratio."""
7878
def fit(self, X, y):
7979
n_pos = np.sum(y)
80-
self.prior = np.log(n_pos / (y.shape[0] - n_pos))
80+
n_neg = y.shape[0] - n_pos
81+
if n_neg == 0 or n_pos == 0:
82+
raise ValueError('y contains non binary labels.')
83+
self.prior = np.log(n_pos / n_neg)
8184

8285
def predict(self, X):
8386
y = np.empty((X.shape[0], 1), dtype=np.float64)

0 commit comments

Comments
 (0)