Skip to content

Instantly share code, notes, and snippets.

@Swarchal
Last active July 24, 2017 14:28
Show Gist options
  • Save Swarchal/7419291f5e75265fd74e2c3dce0b1acc to your computer and use it in GitHub Desktop.
Save Swarchal/7419291f5e75265fd74e2c3dce0b1acc to your computer and use it in GitHub Desktop.
confusion matrix
from sklearn.metrics import confusion_matrix
import numpy as np
cm = confusion_matrix(y_test, predictions)
# normalise confusion matrix for diff sized groups
cm_norm = cm.astype("float") / cm.sum(axis=1)[:, np.newaxis]
# plot confusion matrix
plt.figure(figsize=(8,6))
plt.imshow(cm_norm, interpolation='nearest', cmap=plt.cm.Blues)
plt.title("title")
plt.colorbar()
plt.tight_layout()
tick_marks = np.arange(len(set(feature_names)))
plt.xticks(tick_marks, set(feature_names), rotation = 90)
plt.yticks(tick_marks, set(feature_names))
plt.ylabel('True MOA')
plt.xlabel('Predicted MOA')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment