Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Last active June 14, 2020 17:22
Show Gist options
  • Save rocreguant/916176d570eab91703f596754059eb95 to your computer and use it in GitHub Desktop.
Save rocreguant/916176d570eab91703f596754059eb95 to your computer and use it in GitHub Desktop.
Calibration curve plot in python using sklearn
from sklearn.calibration import calibration_curve
def plot_calibration_curve(y, pred):
plt.figure(figsize=(20, 20))
for i in range(len(class_labels)):
plt.subplot(4, 4, i + 1)
fraction_of_positives, mean_predicted_value = calibration_curve(y[:,i], pred[:,i], n_bins=20)
plt.plot([0, 1], [0, 1], linestyle='--')
plt.plot(mean_predicted_value, fraction_of_positives, marker='.')
plt.xlabel("Predicted Value")
plt.ylabel("Fraction of Positives")
plt.title(class_labels[i])
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment