Python 神经网络输出doen';t拟合测试数据
我用我的训练数据训练神经网络。标签的类别为1或2Python 神经网络输出doen';t拟合测试数据,python,pandas,numpy,neural-network,confusion-matrix,Python,Pandas,Numpy,Neural Network,Confusion Matrix,我用我的训练数据训练神经网络。标签的类别为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
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.
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在里面
---->1份打印(度量值、混淆矩阵(y_测试、pred))
~\.conda\envs\python36\lib\site packages\sklearn\metrics\\u classification.py混淆矩阵(y\u true,y\u pred,标签,样本重量,规格化)
266
267 """
-->268 y_type,y_true,y_pred=_check_targets(y_true,y_pred)
269如果y_类型不在(“二进制”、“多类”):
270提升值错误(“%s不受支持”%y\u类型)
检查目标中的~\.conda\envs\python36\lib\site packages\sklearn\metrics\\u classification.py(y\u true,y\u pred)
80检查长度是否一致(y_true,y_pred)
81 type_true=_目标的类型(y_true)
--->82 type_pred=_目标的类型(y_pred)
83
84 y_type={type_true,type_pred}
目标(y)类型中的~\.conda\envs\python36\lib\site packages\sklearn\utils\multiclass.py
258 if(不是hasattr(y[0],“_u数组_uu”)和isinstance(y[0],序列)
259且不存在(y[0],str)):
-->260 raise VALUERROR('您似乎正在使用旧的多标签数据'
261'表示。序列的顺序为否'
262“不再支持;使用二进制数组或稀疏”
ValueError:您似乎正在使用传统的多标签数据表示法。不再支持序列序列;请改用二进制数组或稀疏矩阵-MultiLabelBinarizer转换器可以转换为此格式。
我如何解决这个问题
谢谢!如果我是你,我会查看以下文档: