gpt4 book ai didi

python - 值错误 : pos_label=1 is not a valid label: array( ['neg' , 'pos'], dtype ='
转载 作者:太空狗 更新时间:2023-10-30 00:04:50 24 4
gpt4 key购买 nike

我在尝试获取召回分数时收到此错误。

X_test = test_pos_vec + test_neg_vec
Y_test = ["pos"] * len(test_pos_vec) + ["neg"] * len(test_neg_vec)

recall_average = recall_score(Y_test, y_predict, average="binary")

print(recall_average)

这会给我:

    C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py:1030: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if pos_label not in present_labels:
Traceback (most recent call last):
File "G:/PyCharmProjects/NB/accuracy/script.py", line 812, in <module>
main()
File "G:/PyCharmProjects/NB/accuracy/script.py", line 91, in main
evaluate_model(model, train_pos_vec, train_neg_vec, test_pos_vec, test_neg_vec, False)
File "G:/PyCharmProjects/NB/accuracy/script.py", line 648, in evaluate_model
recall_average = recall_score(Y_test, y_predict, average="binary")
File "C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py", line 1359, in recall_score
sample_weight=sample_weight)
File "C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py", line 1036, in precision_recall_fscore_support
(pos_label, present_labels))
ValueError: pos_label=1 is not a valid label: array(['neg', 'pos'],
dtype='<U3')

我尝试以这种方式转换 1 中的“pos”和 0 中的“neg”:

for i in range(len(Y_test)):
if 'neg' in Y_test[i]:
Y_test[i] = 0
else:
Y_test[i] = 1

但这给了我另一个错误:

    C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py:181: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
score = y_true == y_pred
Traceback (most recent call last):
File "G:/PyCharmProjects/NB/accuracy/script.py", line 812, in <module>
main()
File "G:/PyCharmProjects/NB/accuracy/script.py", line 91, in main
evaluate_model(model, train_pos_vec, train_neg_vec, test_pos_vec, test_neg_vec, False)
File "G:/PyCharmProjects/NB/accuracy/script.py", line 648, in evaluate_model
recall_average = recall_score(Y_test, y_predict, average="binary")
File "C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py", line 1359, in recall_score
sample_weight=sample_weight)
File "C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\metrics\classification.py", line 1026, in precision_recall_fscore_support
present_labels = unique_labels(y_true, y_pred)
File "C:\Users\anca_elena.moisa\AppData\Local\Programs\Python\Python36\lib\site-packages\sklearn\utils\multiclass.py", line 103, in unique_labels
raise ValueError("Mix of label input types (string and number)")
ValueError: Mix of label input types (string and number)

我想做的是获取指标:准确度、精确度、召回率、f_measure。使用 average='weighted',我得到了相同的结果:accuracy=recall。我猜这是不正确的,所以我更改了 average='binary',但我有这些错误。有什么想法吗?

最佳答案

recall_average = recall_score(Y_test, y_predict, average="binary", pos_label="neg")

使用 "neg""pos" 作为 pos_label 并且此错误不会再次出现。

关于python - 值错误 : pos_label=1 is not a valid label: array( ['neg' , 'pos'], dtype ='<U3'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50203106/

24 4 0

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