我目前正在尝试训练在sklearn中实现的MLPClassifier ...
当我尝试使用给定值训练它时,出现此错误:

ValueError:使用序列设置数组元素。

feature_vector的格式为

[[one_hot_encoded品牌名称],[不同的应用程序缩放为均值0和方差1]]

有人知道我在做什么错吗?

谢谢!





feature_vectors:

[

array([0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,1.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,
        0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]]),

数组([0.82211852,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818、4.45590895,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818、0.3439882,-0.22976818,-0.22976818,-0.22976818,
        4.93403927,-0.22976818,-0.22976818,-0.22976818、0.63086639,
        1.10899671,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,1.58712703,-0.22976818,
        1.77837916,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,2.16088342,-0.22976818,2.16088342,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818、9.42846428,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
        0.91774459,-0.22976818,-0.22976818、4.16903076,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818、2.44776161,
       -0.22976818,-0.22976818,-0.22976818,1.96963129,1.96963129,
        1.96963129,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818、7.13343874,
        5.98592598,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
        3.02151799、4.26465682,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,2.25650948,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
        1.30024884,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818、4.74278714,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,0.3439882,
       -0.22976818、0.3439882,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818、0.53524033,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818、3.49964831,
       -0.22976818,-0.22976818,-0.22976818,-0.22976818,-0.22976818])

]

g_a_group:

[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0.]




MLP:

从sklearn.neural_network导入MLPClassifier

clf = MLPClassifier(solver ='lbfgs',alpha = 1e-5,
                   hidden_​​layer_sizes = [5,2),random_state = 1)

clf.fit(feature_vectors,g_a_group)

最佳答案

从scikit-learn的角度来看,您的数据对.fit调用的预期毫无意义。特征向量应该是大小为N x d的矩阵,其中N-数据点数和d特征数,第二个变量应包含标签,因此,其长度应为N(或N x k,其中k是每点的输出/标签数)。无论变量中所表示的是什么-它们的大小都与它们应表示的大小不匹配。

08-25 00:13