Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多类KerasClassifier的网格搜索_Keras_Grid Search_Hyperparameters_Multiclass Classification - Fatal编程技术网

多类KerasClassifier的网格搜索

多类KerasClassifier的网格搜索,keras,grid-search,hyperparameters,multiclass-classification,Keras,Grid Search,Hyperparameters,Multiclass Classification,我正在尝试使用Keras对多类分类进行网格搜索。以下是代码的一部分: 数据的某些属性如下所示: y_ array(['fast', 'immobile', 'immobile', ..., 'slow', 'immobile', 'slow'], dtype='<U17') y_onehot = pd.get_dummies(y_).values y_onehot array([[1, 0, 0], [0, 0, 1], [0, 0

我正在尝试使用Keras对多类分类进行网格搜索。以下是代码的一部分:

数据的某些属性如下所示:

y_
array(['fast', 'immobile', 'immobile', ..., 'slow',
       'immobile', 'slow'],
      dtype='<U17')

y_onehot = pd.get_dummies(y_).values

y_onehot
array([[1, 0, 0],
       [0, 0, 1],
       [0, 0, 1],
    ...
       [0, 1, 0],
       [0, 0, 1],
       [0, 1, 0]], dtype=uint8)

#Do train-test split

y_train.shape
(1904,)

y_train_onehot.shape
(1904, 3)
下面是错误:

--> grid_result = grid.fit(X_train, y_train_onehot)
ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass targets

这段代码是针对二进制模型的,但我希望能针对多类数据集对其进行修改。请帮忙。谢谢

错误在softmax层中

我想你指的是
y\u-train\u-onehot.shape[1]
而不是
y\u-train\u-onehot[1]

更新1:这很奇怪,但您的第二个问题似乎是您的培训问题,您是否介意尝试两种方法:

  • 在y_列车上尝试相同型号的而不使用onehot编码
  • 如果仅此一项不起作用,请将损失更改为
    sparse\u categorical\u crossentropy

  • 另外,请确保将
    y\u-train\u-onehot.shape[1]
    更改为softmax层中的类数

    是否可以显示您的
    y-train\u-onehot
    和原始
    y
    的一些示例?您将原始的
    y
    转换为
    y\u onehot
    @VivekKumar的代码,我已经按照您的建议进行了添加。它看起来像一个简单的多类问题。请不要对
    y.
    进行热编码。直接在
    fit()
    grid.fit(X\u-train,y\u-train)
    中使用它。我有一个类似的问题,你能更明确地说明你的尝试吗?恢复到非热编码似乎会产生各种其他问题,这些问题也不起作用(例如必须将最后一个softmax设置为layer,将其设置为dimension 1,等等)。谢谢
    --> grid_result = grid.fit(X_train, y_train_onehot)
    ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass targets