ValueError: pos_label=1 is not a valid label: array(['neg', 'pos'], dtype='
ValueError: pos_label=1 is not a valid label: array(['neg', 'pos'], dtype='
在尝试获取召回率时,我收到了以下错误消息:
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
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='
我尝试将'pos'转换为1,'neg'转换为0:
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
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)
我尝试获取准确率、精确率、召回率和F1值。使用average='weighted'
时,我得到相同结果:准确率=召回率。我猜这是不正确的,所以我改变了average='binary'
,但是我遇到了这些错误。有什么想法吗?
在尝试获取召回率时,我收到了以下错误消息:
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, inmain() 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='
我尝试将'pos'转换为1,'neg'转换为0:
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, inmain() 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)
我尝试获取准确率、精确率、召回率和F1值。使用
average='weighted'
时,我得到相同结果:准确率=召回率。我猜这是不正确的,所以我改变了average='binary'
,但是我遇到了这些错误。有什么想法吗?