Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Created June 14, 2020 17:24
Show Gist options
  • Save rocreguant/cccaabc1be933e0885675e34555f5272 to your computer and use it in GitHub Desktop.
Save rocreguant/cccaabc1be933e0885675e34555f5272 to your computer and use it in GitHub Desktop.
Deep learning model calibration using Platt scaling approach via sklearn
from sklearn.linear_model import LogisticRegression as LR
y_train = train_results[class_labels].values
pred_train = train_results[pred_labels].values
pred_calibrated = np.zeros_like(pred)
for i in range(len(class_labels)):
lr = LR(solver='liblinear', max_iter=10000)
lr.fit(pred_train[:, i].reshape(-1, 1), y_train[:, i])
pred_calibrated[:, i] = lr.predict_proba(pred[:, i].reshape(-1, 1))[:,1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment