gpt4 book ai didi

python - 值错误 : continuous format is not supported

转载 作者:太空狗 更新时间:2023-10-29 20:57:51 24 4
gpt4 key购买 nike

我写了一个简单的函数,我正在使用 average_precision_scorescikit-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)

执行该函数时,会产生以下错误。

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

如果我打印两个 numpy 数组 predictionsgold_predictions,例如,它看起来不错。 [下面提供了一个示例。]

[ 0.40865014  0.26047812  0.07588802  0.26604077  0.10586583  0.17118802
0.26797949 0.34618672 0.33659923 0.22075308 0.42288553 0.24908153
0.26506338 0.28224747 0.32942101 0.19986877 0.39831917 0.23635269
0.34715138 0.39831917 0.23635269 0.35822859 0.12110706]
[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]

我在这里做错了什么?报错是什么意思?

最佳答案

看看sklearn docs

Parameters:

y_true : array, shape = [n_samples] or [n_samples, n_classes] True binary labels in binary label indicators.

y_score : array, shape = [n_samples] or [n_samples, n_classes] Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by “decision_function” on some classifiers).

因此,您的第一个参数必须是二进制标签数组,但您传递的是某种 float 组作为第一个参数。所以我认为您需要颠倒传递的参数的顺序。

关于python - 值错误 : continuous format is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44468172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com