使用以下代码运行Keras多类分类模型时出错时获取值错误:
model2 = Sequential()
model2.add(Dense(200, input_shape=(4132,), activation='relu'))
model2.add(Dense(200, activation='relu'))
model2.add(Dense(31, activation='softmax'))
SGD = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model2.compile(optimizer=SGD,
loss='categorical_crossentropy',
metrics=['accuracy'])
model2.fit(x_train, y_train, epochs=100, verbose=2) ---> Error on this line
错误:
Train Shape: (4132, 49)
Test Shape: (1033, 49)
Traceback (most recent call last):
File "ANN.py", line 213, in <module>
model2.fit(x_train, y_train, epochs=100, verbose=2)
File "C:\Users\C256121\AppData\Local\Programs\Python\Python36\lib\site-package
s\keras\models.py", line 960, in fit
validation_steps=validation_steps)
File "C:\Users\C256121\AppData\Local\Programs\Python\Python36\lib\site-package
s\keras\engine\training.py", line 1574, in fit
batch_size=batch_size)
File "C:\Users\C256121\AppData\Local\Programs\Python\Python36\lib\site-package
s\keras\engine\training.py", line 1407, in _standardize_user_data
exception_prefix='input')
File "C:\Users\C256121\AppData\Local\Programs\Python\Python36\lib\site-package
s\keras\engine\training.py", line 128, in _standardize_input_data
arrays[i] = array
ValueError: could not broadcast input array from shape (49,1) into shape (49)
我在目标变量中有31个类。请帮忙。