我想使用 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/