Skip to content

Instantly share code, notes, and snippets.

View HaritzPuerto's full-sized avatar

Haritz Puerto HaritzPuerto

View GitHub Profile
@HaritzPuerto
HaritzPuerto / confusion_matrix_between_two_pytorch_tensors.py
Created June 6, 2020 06:43 — forked from the-bass/confusion_matrix_between_two_pytorch_tensors.py
Calculating the confusion matrix between two PyTorch tensors (a batch of predictions) - Last tested with PyTorch 0.4.1
import torch
def confusion(prediction, truth):
""" Returns the confusion matrix for the values in the `prediction` and `truth`
tensors, i.e. the amount of positions where the values of `prediction`
and `truth` are
- 1 and 1 (True Positive)
- 1 and 0 (False Positive)
- 0 and 0 (True Negative)