今天在使用sklearn_crfsuite.metrics.flat_classification_report函数的时候突然报错:TypeError: classification_report() takes 2 positional arguments but 3 were given,这里对该函数进行了详细剖析,找到报错原因,并给出解决办法。
函数详细剖析
使用sklearn_crfsuite拓展包中的metrics查看指标
from sklearn_crfsuite import metrics
# y_true为真实标签、y_pred为预测标签、labels为想要查看指标的标签(通常去除'O')print(metrics.flat_classification_report(y_true, y_pred, labels=sort_labels))
from sklearn import metrics
y_true =[label for y in y_true for label in y]
y_pred =[label for y in y_pred for label in y]print(metrics.classification_report(
y_true, y_pred, labels=sort_labels
))
或者使用sklearn_crfsuite里的方式进行展平
from sklearn import metrics
from itertools import chain
y_true =list(chain.from_iterable(y_true))
y_pred =list(chain.from_iterable(y_pred))print(metrics.classification_report(
y_true, y_pred, labels=sort_labels
))