Spaces:
Sleeping
Sleeping
File size: 469 Bytes
0079b8d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import evaluate
_accuracy_metric = evaluate.load("accuracy")
def accuracy(predictions, y):
unique_values = set(y + predictions)
label_mapping = {label: i for i, label in enumerate(unique_values)}
true_labels = [label_mapping[value] for value in y]
pred_labels = [label_mapping[value] for value in predictions]
# Compute accuracy
result = _accuracy_metric.compute(predictions=pred_labels, references=true_labels)
return result["accuracy"]
|