From dbf5ddb1c77805fd5142399c3f820bd3cbaba53a Mon Sep 17 00:00:00 2001 From: Zayd Hammoudeh Date: Wed, 2 Jan 2019 17:54:18 -0800 Subject: [PATCH] Fix for issue #12896. Switching calibration module to use scipy's expit function instead of directly using np.exp --- sklearn/calibration.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sklearn/calibration.py b/sklearn/calibration.py index e1ec2bd3cf596..9853c85a1dadd 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.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])) l = -(T * np.log(P + tiny) + T1 * np.log(1. - P + tiny)) if sample_weight is not None: return (sample_weight * l).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):