运用Roberta模型对文本进行分类后,评估F1,precission等出现了以下问题,该如何解决:
print (classification_report(y_test, y_pred))
ValueError Traceback (most recent call last)
/tmp/ipykernel_18752/4076745676.py in <module>
----> 1 print (classification_report(y_test, y_pred))
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in classification_report(y_true, y_pred, labels, target_names, sample_weight, digits, output_dict, zero_division)
2074 """
2075
-> 2076 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
2077
2078 if labels is None:
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in _check_targets(y_true, y_pred)
93 raise ValueError(
94 "Classification metrics can't handle a mix of {0} and {1} targets".format(
---> 95 type_true, type_pred
96 )
97 )
ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets
print('F1 Score:', f1_score(X_test, y_test))
print('precision:', precision_score(X_test, y_test))
print('recall:', recall_score(X_test, y_test))
ValueError Traceback (most recent call last)
/tmp/ipykernel_18752/1070155529.py in <module>
----> 1 print('F1 Score:', f1_score(X_test, y_test))
2 print('precision:', precision_score(X_test, y_test))
3 print('recall:', recall_score(X_test, y_test))
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in f1_score(y_true, y_pred, labels, pos_label, average, sample_weight, zero_division)
1119 average=average,
1120 sample_weight=sample_weight,
-> 1121 zero_division=zero_division,
1122 )
1123
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in fbeta_score(y_true, y_pred, beta, labels, pos_label, average, sample_weight, zero_division)
1258 warn_for=("f-score",),
1259 sample_weight=sample_weight,
-> 1260 zero_division=zero_division,
1261 )
1262 return f
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in precision_recall_fscore_support(y_true, y_pred, beta, labels, pos_label, average, warn_for, sample_weight, zero_division)
1532 if beta < 0:
1533 raise ValueError("beta should be >=0 in the F-beta score")
-> 1534 labels = _check_set_wise_labels(y_true, y_pred, average, labels, pos_label)
1535
1536 # Calculate tp_sum, pred_sum, true_sum ###
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in _check_set_wise_labels(y_true, y_pred, average, labels, pos_label)
1336 raise ValueError("average has to be one of " + str(average_options))
1337
-> 1338 y_type, y_true, y_pred = _check_targets(y_true, y_pred)
1339 # Convert to Python primitive type to avoid NumPy type / Python str
1340 # comparison. See https://github.com/numpy/numpy/issues/6784
/environment/miniconda3/lib/python3.7/site-packages/sklearn/metrics/_classification.py in _check_targets(y_true, y_pred)
82 y_pred : array or indicator matrix
83 """
---> 84 check_consistent_length(y_true, y_pred)
85 type_true = type_of_target(y_true)
86 type_pred = type_of_target(y_pred)
/environment/miniconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_consistent_length(*arrays)
331 raise ValueError(
332 "Found input variables with inconsistent numbers of samples: %r"
--> 333 % [int(l) for l in lengths]
334 )
335
ValueError: Found input variables with inconsistent numbers of samples: [3, 22500]
请大家指点一下,非常感谢!
应该是你数据的问题,可能标签和分类数量对不上,纯看报错信息的话
之前老师指导了一下,我对照着加上以下代码:
for_labels_pred=list()
for_labels_real=list(),
如果后面是list(),是空值,该怎么修改一下呢?麻烦大家帮我看看!