我试图从python CRFsuite获得混淆矩阵
这是我的代码:
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, pred_y, normalize='true', labels=lables)
错误:
ValueError: You appear to be using a legacy multi-label data representation. Sequence of sequences are no longer supported; use a binary array or sparse matrix instead - the MultiLabelBinarizer transformer can convert to this format.
我试图使用MultiLabelBinarizer()
,但仍然无法获得混淆矩阵
在谷歌搜索之后,我发现了这个answer,它说对于混淆矩阵函数,必须展平y_test
和pred_y
。我查看了CRFsuite的源代码,用于其他度量here,它们确实使用了fallaten函数:
def _flattens_y(func):
@wraps(func)
def wrapper(y_true, y_pred, *args, **kwargs):
y_true_flat = flatten(y_true)
y_pred_flat = flatten(y_pred)
return func(y_true_flat, y_pred_flat, *args, **kwargs)
return wrapper
但是没有获取confusion matrix
的函数
y_test
和pred_y
是嵌套列表
如何展平y_test
和pred_y
以获得混淆矩阵
多谢各位
相关问题 更多 >
编程相关推荐