我已经写了,我现在用的是一个简单的函数average_precision_score从scikit-learn计算平均精度.
我的代码:
def compute_average_precision(predictions, gold):
gold_predictions = np.zeros(predictions.size, dtype=np.int)
for idx in range(gold):
gold_predictions[idx] = 1
return average_precision_score(predictions, gold_predictions)
Run Code Online (Sandbox Code Playgroud)
执行该函数时,会产生以下错误.
Traceback (most recent call last):
File "test.py", line 91, in <module>
total_avg_precision += compute_average_precision(np.asarray(probs), len(gold_candidates))
File "test.py", line 29, in compute_average_precision
return average_precision_score(predictions, gold_predictions)
File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/sklearn/metrics/ranking.py", line 184, in average_precision_score
average, sample_weight=sample_weight)
File "/if5/wua4nw/anaconda3/lib/python3.5/site-packages/sklearn/metrics/base.py", line 81, in _average_binary_score
raise ValueError("{0} format is not supported".format(y_type))
ValueError: continuous format is not supported
Run Code Online (Sandbox Code Playgroud)
如果我打印两个numpy的阵列predictions和gold_predictions,说了一个例子,它看起来没事.[下面提供了一个例子.]
[ …Run Code Online (Sandbox Code Playgroud)