问题描述
我用train_data训练神经网络。标签的类别为1或2。
pred = pd.Series(model.predict(X_test_tok).tolist())
这就是我准备预测的方式。所以我得到:
0 [1.0]
1 [1.0]
2 [1.0]
3 [1.0]
4 [1.0]
...
2380 [1.0]
2381 [1.0]
2382 [1.0]
2383 [1.0]
2384 [1.0]
Length: 2385,dtype: object
我的测试数据如下:
626 1
4677 1
1580 2
3749 1
3280 1
..
5321 1
1232 1
5674 1
2863 2
3656 1
Name: Zielvar,Length: 2385,dtype: object
因此混淆矩阵的代码将失败:
print(metrics.confusion_matrix(y_test,pred))
该错误包括以下内容:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-19-a22a78d1c59c> in <module>
----> 1 print(metrics.confusion_matrix(y_test,pred))
~\.conda\envs\python36\lib\site-packages\sklearn\metrics\_classification.py in confusion_matrix(y_true,y_pred,labels,sample_weight,normalize)
266
267 """
--> 268 y_type,y_true,y_pred = _check_targets(y_true,y_pred)
269 if y_type not in ("binary","multiclass"):
270 raise ValueError("%s is not supported" % y_type)
~\.conda\envs\python36\lib\site-packages\sklearn\metrics\_classification.py in _check_targets(y_true,y_pred)
80 check_consistent_length(y_true,y_pred)
81 type_true = type_of_target(y_true)
---> 82 type_pred = type_of_target(y_pred)
83
84 y_type = {type_true,type_pred}
~\.conda\envs\python36\lib\site-packages\sklearn\utils\multiclass.py in type_of_target(y)
258 if (not hasattr(y[0],'__array__') and isinstance(y[0],Sequence)
259 and not isinstance(y[0],str)):
--> 260 raise ValueError('You appear to be using a legacy multi-label data'
261 ' representation. Sequence of sequences are no'
262 ' longer supported; use a binary array or sparse'
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.
我该如何解决这个问题?
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)