Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. from sklearn.metrics import confusion_matrix
  2. from sklearn.utils.multiclass import unique_labels
  3. import itertools
  4.  
  5.  
  6. def plot_confusion_matrix(cm, classes, normalize=False, title='Confusion matrix',
  7. cmap=plt.cm.Blues):
  8. # Função importada dos exemplos do SKLearn
  9. if normalize:
  10. cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]
  11.  
  12. plt.imshow(cm, interpolation='nearest', cmap=cmap)
  13. plt.title(title)
  14. plt.colorbar()
  15. tick_marks = np.arange(len(classes))
  16. plt.xticks(tick_marks, classes, rotation=45)
  17. plt.yticks(tick_marks, classes)
  18.  
  19. fmt = '.2f' if normalize else 'd'
  20. thresh = cm.max() / 2.
  21. for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):
  22. plt.text(j, i, format(cm[i, j], fmt),
  23. horizontalalignment="center",
  24. color="white" if cm[i, j] > thresh else "black")
  25.  
  26. plt.ylabel('True label')
  27. plt.xlabel('Predicted label')
  28. plt.tight_layout()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement