简体   繁体   English

从 python CRFSuite 获取混淆矩阵的最简单方法是什么?

[英]What is the easiest way to obtain the confusion matrix from python CRFSuite?

I am trying to obtain the confusion matrix from python CRFsuite .我正在尝试从python CRFsuite获取混淆矩阵。

This my code:这是我的代码:

from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, pred_y, normalize='true', labels=lables)

error:错误:

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.

I tried to use MultiLabelBinarizer() , but still couldn't get the confusion matrix.我尝试使用MultiLabelBinarizer() ,但仍然无法获得混淆矩阵。

After googling around I found this answer , it says that for the confusion matrix function you have to flatten the y_test and pred_y .在谷歌搜索后我找到了这个答案,它说对于混淆矩阵 function 你必须展平y_testpred_y I took a look at the source code of CRFsuite for other metrics here , they do use a fallaten function:我在这里查看了其他指标的 CRFsuite 的源代码,它们确实使用了一个错误的 function:

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

But there is no function for obtaining the confusion matrix .但是没有用于获得confusion matrix的 function 。

The y_test and pred_y are nested lists. y_testpred_y是嵌套列表。

How can I flatten the y_test and pred_y to obtain the confusion matrix?y_testpred_y以获得混淆矩阵?

Thank you.谢谢你。

from itertools import chain

f_y_test = list(chain.from_iterable(y_test))
f_pred_y = list(chain.from_iterable(pred_y))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sci-kit:使用 GridSearchCV 时获得估计器混淆矩阵的最简单方法是什么? - Sci-kit: What's the easiest way to get the confusion matrix of an estimator when using GridSearchCV? 使用python解决矩阵逆的最简单方法是什么 - What is the easiest way to solve matrix inverse using python 使用Python执行模块化矩阵反转的最简单方法? - Easiest way to perform modular matrix inversion with Python? 在Python中从文件加载数组数据的最简单方法是什么? - what's the easiest way to load array data from a file in Python? 从Python读取FoxPro DBF文件最简单的方法是什么? - What's the easiest way to read a FoxPro DBF file from Python? 检查Aerospike集是否为python空的最简单方法是什么? - What is the easiest way to check if aerospike set is empty from python? 在 Python 中转义 HTML 的最简单方法是什么? - What's the easiest way to escape HTML in Python? 用Python制作表格的最简单方法是什么? - What's the easiest way to make a table in Python? 在Python中处理日期/时间的最简单方法是什么? - What is the easiest way to handle dates/times in Python? python 中的最佳方法是从已经聚合的表中创建混淆矩阵,其中包含实际标签和预测标签的计数 - What is the best way in python to create a confusion matrix out of an already aggregated table with counts of actual labels and predicted labels
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM