Spaces:
Sleeping
Sleeping
import evaluate | |
from datasets import Features, Value | |
from sklearn.metrics import accuracy_score | |
_CITATION = """ | |
@article{scikit-learn, | |
title={Scikit-learn: Machine Learning in {P}ython}, | |
author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V. | |
and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P. | |
and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and | |
Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.}, | |
journal={Journal of Machine Learning Research}, | |
volume={12}, | |
pages={2825--2830}, | |
year={2011} | |
} | |
""" | |
_DESCRIPTION = """ | |
Accuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with: | |
Accuracy = (TP + TN) / (TP + TN + FP + FN) | |
Where: | |
TP: True positive | |
TN: True negative | |
FP: False positive | |
FN: False negative | |
""" | |
_KWARGS_DESCRIPTION = """ | |
Args: | |
predictions (`list` of `str`): Predicted labels. | |
references (`list` of `str`): Ground truth labels. | |
Returns: | |
accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy. | |
""" | |
class ClassificationEvaluatorTest(evaluate.Metric): | |
def _info(self): | |
return evaluate.MetricInfo( | |
description=_DESCRIPTION, | |
citation=_CITATION, | |
inputs_description=_KWARGS_DESCRIPTION, | |
features=Features( | |
{"predictions": Value("string"), "references": Value("string")} | |
), | |
) | |
def _compute(self, predictions, references): | |
return { | |
"accuracy": float( | |
accuracy_score( | |
references, predictions, normalize=True, sample_weight=None | |
) | |
) | |
} | |