diff --git a/sklearn/calibration.py b/sklearn/calibration.py index 600be8d603da7..b563cdee143cb 100644 --- a/sklearn/calibration.py +++ b/sklearn/calibration.py @@ -14,6 +14,7 @@ from math import log import numpy as np +from scipy.special import expit from scipy.special import xlogy from scipy.optimize import fmin_bfgs from sklearn.preprocessing import LabelEncoder @@ -442,8 +443,7 @@ def _sigmoid_calibration(df, y, sample_weight=None): def objective(AB): # From Platt (beginning of Section 2.2) - E = np.exp(AB[0] * F + AB[1]) - P = 1. / (1. + E) + P = expit(-(AB[0] * F + AB[1])) loss = -(xlogy(T, P) + xlogy(T1, 1. - P)) if sample_weight is not None: return (sample_weight * loss).sum() @@ -517,7 +517,7 @@ def predict(self, T): The predicted data. """ T = column_or_1d(T) - return 1. / (1. + np.exp(self.a_ * T + self.b_)) + return expit(-(self.a_ * T + self.b_)) def calibration_curve(y_true, y_prob, normalize=False, n_bins=5):