[英]Sci-kit: What's the easiest way to get the confusion matrix of an estimator when using GridSearchCV?
[英]What is the easiest way to obtain the confusion matrix from python CRFSuite?
我正在嘗試從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()
,但仍然無法獲得混淆矩陣。
在谷歌搜索后我找到了這個答案,它說對於混淆矩陣 function 你必須展平y_test
和pred_y
。 我在這里查看了其他指標的 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
但是沒有用於獲得confusion matrix
的 function 。
y_test
和pred_y
是嵌套列表。
如y_test
和pred_y
以獲得混淆矩陣?
謝謝你。
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.