Got it! You want to treat the numeric values as exact matches or not, turning the problem into a binary classification:
- True Positive (TP): predicted value equals true value (correct)
- False Positive (FP): predicted value does not equal true value but predicted as correct (in your case, this might not apply since you only have one prediction per instance)
- False Negative (FN): predicted value does not equal true value (incorrect)
- True Negative (TN): not really applicable here because each instance either matches or not
Since each instance is either correct (1) or incorrect (0), you can build a confusion matrix like this:
| Predicted Correct (1) | Predicted Incorrect (0) |
|---|
| True Correct (1) | TP | FN |
| True Incorrect (0) | FP | TN |
But in your case:
- True label: 1 if predicted value == true value, else 0
- Predicted label: same as true label (since you only have one prediction per instance)
So effectively, you want to compute:
- TP: number of instances where predicted == true value (correct)
- FN: number of instances where predicted != true value (incorrect)
- FP and TN: not really applicable unless you have a separate prediction of correctness
What you want is:
- For each instance, label it as 1 if predicted == true value, else 0
- Then compute metrics like accuracy, precision, recall, F1-score treating "correct" as positive class
Example in Python:
from sklearn.metrics import confusion_matrix, precision_score, recall_score, f1_score, accuracy_score
# True values (gold standard)
true_values = [10, 20, 30, 40, 50]
# Predicted values
pred_values = [10, 21, 30, 39, 50]
# Create binary labels: 1 if predicted == true, else 0
true_labels = [1] * len(true_values) # gold standard is always "correct"
pred_labels = [1 if p == t else 0 for p, t in zip(pred_values, true_values)]
# Compute confusion matrix
cm = confusion_matrix(true_labels, pred_labels)
print("Confusion Matrix:\n", cm)
# Compute metrics
accuracy = accuracy_score(true_labels, pred_labels)
precision = precision_score(true_labels, pred_labels)
recall = recall_score(true_labels, pred_labels)
f1 = f1_score(true_labels, pred_labels)
print(f"Accuracy: {accuracy:.2f}")
print(f"Precision: {precision:.2f}")
print(f"Recall: {recall:.2f}")
print(f"F1-score: {f1:.2f}")