python-3.x - 断言错误: Mismatch between dataset size and units in output layer

标签 python-3.x machine-learning scikit-learn neural-network

我想使用 scikit-neuralnetwork 进行 NN 分类,我有 5 个类,因此在输出层中,我的单位=5 但我收到此错误:数据集大小与输出层中的单位不匹配, 我根据文档 reshape 了 y_train 并将“Sigmoid”函数应用于输出层: http://scikit-neuralnetwork.readthedocs.io/en/latest/guide_model.html#classification

If you want to do multi-label classification, simply fit using a y array of integers that has multiple dimensions, e.g. shape (N, 3) for three different classes. Then, make sure the last layer is Sigmoid instead.

y_train 形状为:(2115, 5) X_train 形状为:(2115, 343) 这是代码:

import sknn.mlp as mlp
from sknn.mlp import Classifier
ip_layer = mlp.Layer('Sigmoid', units=1)
hidden_layer = mlp.Layer('Tanh', units=100)
op_layer = mlp.Layer('Sigmoid', units=5) 

nn = Classifier(
    [ip_layer, hidden_layer, op_layer],
    n_iter=10000
)
nn.fit(X_train, y_train)

最佳答案

输入层有一个单元。

如果您设置ip_layer = mlp.Layer('Sigmoid',units=343)它应该可以工作。

关于python-3.x - 断言错误: Mismatch between dataset size and units in output layer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36966957/

相关文章:

python - 如何在 Python 中将来自 Web 的原始 html 转换为可解析的 xml

python - heroku 上的 Peewee 和 postgres,无法创建表

python - 广而深的tensorflow教程: Why do you test using only a batch of your evaluation dataset?

python - Accuracy_score 出现错误

python - 如何使用 Apache Spark 执行简单的网格搜索

python - 如何保存 Keras 回归模型?

python - 基于过滤器的列计算?

python - 如何在 Python 中对 3D 数组应用克里金法?

python - Scikit-learn安装: "ImportError: No module named sklearn"

python - Python 3x 的最佳机器学习包?