我们在使用MLP分类器sklearn.neural_网络并对分类器产生的偏差和权重进行了分析。在
当我们有二进制数据时会有一个问题,即只允许两个值。最后一层的尺寸似乎是1,而不是2。 在其他情况下,偏压和权重的形状似乎总是与输出值的数量相匹配。在
binary_classifier= MLPClassifier().fit(np.matrix([[0.], [1.]]), np.array([0,1]))
other_classifier = MLPClassifier().fit(np.matrix([[0.], [1.], [2]]), np.array([0,1,2]))
# Note that the dimension below is 1
print(binary_classifier.intercepts_[-1].shape, binary_classifier.coefs_[-1].shape)
# Note that the dimension below is 3
print(other_classifier.intercepts_[-1].shape, other_classifier.coefs_[-1].shape)
输出:
^{pr2}$从数学上讲,你能做到这一点是有道理的,我假设这是一个优化,但我们失去了泛化能力。 有没有一种简单的方法可以阻止scikit这样做?我们如何转换权重和偏差,使它们的尺寸与值的数量相匹配?在
神经网络的类标签需要一个热编码,而这是在
MLPClassifier
背后发生的。如果显式地传入一个热编码目标,则会获得所需的输出:输出:
^{pr2}$关于如何执行这个预处理步骤的更多信息,我将查看scikit中的
OneHotEncoder
documentation。在相关问题 更多 >
编程相关推荐