Skip to content

Commit 8453daa

Browse files
pjknkdaamueller
authored andcommitted
Use expit function to compute the probability in ExponentialLoss class.
1 parent 99ed481 commit 8453daa

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

sklearn/ensemble/gradient_boosting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def _update_terminal_region(self, tree, terminal_regions, leaf, X, y,
505505

506506
def _score_to_proba(self, score):
507507
proba = np.ones((score.shape[0], 2), dtype=np.float64)
508-
proba[:, 1] = 1.0 / (1.0 + np.exp(-score.ravel()))
508+
proba[:, 1] = expit(score.ravel())
509509
proba[:, 0] -= proba[:, 1]
510510
return proba
511511

@@ -628,7 +628,7 @@ def _update_terminal_region(self, tree, terminal_regions, leaf, X, y,
628628

629629
def _score_to_proba(self, score):
630630
proba = np.ones((score.shape[0], 2), dtype=np.float64)
631-
proba[:, 1] = 1.0 / (1.0 + np.exp(-2.0 * score.ravel()))
631+
proba[:, 1] = expit(2.0 * score.ravel())
632632
proba[:, 0] -= proba[:, 1]
633633
return proba
634634

sklearn/ensemble/tests/test_gradient_boosting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,8 @@ def test_probability_exponential():
962962
assert np.all(y_proba >= 0.0)
963963
assert np.all(y_proba <= 1.0)
964964
score = clf.decision_function(T).ravel()
965-
assert_array_equal(y_proba[:, 1],
966-
1.0 / (1.0 + np.exp(-2 * score)))
965+
assert_array_almost_equal(y_proba[:, 1],
966+
1.0 / (1.0 + np.exp(-2 * score)))
967967

968968
# derive predictions from probabilities
969969
y_pred = clf.classes_.take(y_proba.argmax(axis=1), axis=0)
@@ -990,14 +990,14 @@ def test_non_uniform_weights_toy_min_weight_leaf():
990990
[1, 0],
991991
[1, 0],
992992
[0, 1],
993-
]
993+
]
994994
y = [0, 0, 1, 0]
995995
# ignore the first 2 training samples by setting their weight to 0
996996
sample_weight = [0, 0, 1, 1]
997997
gb = GradientBoostingRegressor(n_estimators=5, min_weight_fraction_leaf=0.1)
998998
gb.fit(X, y, sample_weight=sample_weight)
999999
assert_true(gb.predict([[1, 0]])[0] > 0.5)
1000-
assert_almost_equal(gb.estimators_[0,0].splitter.min_weight_leaf, 0.2)
1000+
assert_almost_equal(gb.estimators_[0, 0].splitter.min_weight_leaf, 0.2)
10011001

10021002

10031003
def test_non_uniform_weights_toy_edge_case_clf():

0 commit comments

Comments
 (0)