average has to be one of (param0)
Package:
scikit-learn
47032

Exception Class:
ValueError
Raise code
""" e : float or array of shape [n_classes]
If not ``None``, average the score, else return the score for each
classes.
"""
average_options = (None, 'micro', 'macro', 'weighted', 'samples')
if average not in average_options:
raise ValueError('average has to be one of {0}'
''.format(average_options))
y_type = type_of_target(y_true)
if y_type not in ("binary", "multilabel-indicator"):
raise ValueError("{0} format is not supported".format(y_type))
if y_type == "binary":
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/scikit-learn/scikit-learn/blob/c67518350f91072f9d37ed09c5ef7edf555b6cf6/sklearn/metrics/_base.py#L69Ways to fix
average should be one of the following values.
{'micro', 'samples', 'weighted', 'macro'} or None,
Steps to reproduce the exception:
import numpy as np
from sklearn.metrics import average_precision_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
result = average_precision_score(y_true, y_scores,average="micr")
print(result)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-07d5e8a098dc> in <module>() 3 y_true = np.array([0, 0, 1, 1]) 4 y_scores = np.array([0.1, 0.4, 0.35, 0.8]) ----> 5 result = average_precision_score(y_true, y_scores,average="micr") 6 print(result)
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_ranking.py in average_precision_score(y_true, y_score, average, pos_label, sample_weight) 231 ) 232 return _average_binary_score( --> 233 average_precision, y_true, y_score, average, sample_weight=sample_weight 234 ) 235
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_base.py in _average_binary_score(binary_metric, y_true, y_score, average, sample_weight) 66 average_options = (None, "micro", "macro", "weighted", "samples") 67 if average not in average_options: ---> 68 raise ValueError("average has to be one of {0}".format(average_options)) 69 70 y_type = type_of_target(y_true)
ValueError: average has to be one of (None, 'micro', 'macro', 'weighted', 'samples')
Fixed version of the code:
import numpy as np
from sklearn.metrics import average_precision_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
result = average_precision_score(y_true, y_scores,average="micro")
print(result)
0.8333333333333333
Add a possible fix
Please authorize to post fix