How can you set up a binary classification task?
labels = rng.integers(low=0, high=2, size=n_samples, dtype=int)
logits = torch.tensor(rng.uniform(low=-10, high=10, size=n_samples))
outputs = torch.sigmoid(logits)
threshold = 0.5
predictions = (outputs >= threshold).long()
# long() transforms boolean to 0 for False and 1 for True
How can you use a confusion matrix?
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_true=labels, y_pred=predictions)
# you can use different predefined evaluation metrics,
# such like accuracy_score() (accuracy), balanced_accuracy_score()
# (balanced accuracy), etc.
Last changed2 years ago