我想用keras创建一个模型,但是我在构建模型时遇到了一些问题。我试着把它放进去 model.fit
, np.array
对于x_列和y_列,但返回相同的错误。
这是密码
X_train, y_train, X_test, y_test = train_test_split(X, y, test_size=0.2)
model = keras.Sequential([
keras.layers.Flatten(input_shape=(3,)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(64, activation='relu'),
keras.layers.Dense(3, activation='softmax')
])
# compile model
optimiser = keras.optimizers.Adam(learning_rate=0.0001)
model.compile(optimizer=optimiser,
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.summary()
# train model
model.fit(X_train, y_train, validation_data=(X_test, y_test), batch_size=32, epochs=100)
错误
ValueError: Data cardinality is ambiguous:
x sizes: 4928
y sizes: 1233
Make sure all arrays contain the same number of samples.
暂无答案!
目前还没有任何答案,快来回答吧!