Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions betacal/beta_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ def _beta_calibration(df, y, sample_weight=None):
lr = LogisticRegression(C=99999999999)
lr.fit(x, y, sample_weight)
coefs = lr.coef_[0]
a = 0
a = None
b = coefs[0]
elif coefs[1] < 0:
x = x[:, 0].reshape(-1, 1)
lr = LogisticRegression(C=99999999999)
lr.fit(x, y, sample_weight)
coefs = lr.coef_[0]
a = coefs[0]
b = 0
b = None
else:
a = coefs[0]
b = coefs[1]
inter = lr.intercept_[0]

m = minimize_scalar(lambda mh: np.abs(b*np.log(1.-mh)-a*np.log(mh)-inter),
a_, b_ = a or 0, b or 0
m = minimize_scalar(lambda mh: np.abs(b_*np.log(1.-mh)-a_*np.log(mh)-inter),
bounds=[0, 1], method='Bounded').x
map = [a, b, m]
return map, lr
Expand Down Expand Up @@ -112,9 +113,9 @@ def predict(self, S):
x = np.hstack((df, 1. - df))
x = np.log(x)
x[:, 1] *= -1
if self.map_[0] == 0:
if self.map_[0] == None:
x = x[:, 1].reshape(-1, 1)
elif self.map_[1] == 0:
elif self.map_[1] == None:
x = x[:, 0].reshape(-1, 1)

return self.lr_.predict_proba(x)[:, 1]
Expand Down