发现与任何模型输出不对应的意外损失或指标

问题描述 投票:0回答:0

我的数据集中有三列,即“student_star”、“student_difficult”和“comments”。我需要根据评论训练模型,通过单个模型预测“student_star”和“student_difficult”的 2 个值。

# Create the GRU model
model = keras.models.Sequential()
model.add(keras.layers.Embedding(num_words, embedding_dim, weights=[embedding_matrix], input_length=max_length, trainable=False))
model.add(keras.layers.GRU(128, return_sequences=True))
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.GRU(64))
model.add(keras.layers.Dropout(0.5))
model.add(keras.layers.Dense(32, activation='relu'))

# Output layer for 'student_star' and 'student_difficult'
model.add(keras.layers.Dense(6, activation='softmax', name='student_star'))
model.add(keras.layers.Dense(4, activation='softmax', name='student_difficult'))

# Compile the model with a different optimizer
optimizer = keras.optimizers.RMSprop(lr=0.001)
model.compile(optimizer=optimizer, loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# Print the model summary
model.summary()

以上是我在以下数据集上训练的模型:

# Drop rows with null values in 'comments' column
data_frame.dropna(subset=['comments'], inplace=True)

# Select only the 'student_star' and 'comments' columns
data_frame = data_frame[['student_star', 'student_difficult', 'comments']]

当我尝试使用以下代码拟合模型时,它会抛出一个错误:

# Train the model on the training data
model.fit(X_train_pad, {'student_star': y_train['student_star'], 'student_difficult': y_train['student_difficult']}, 
          epochs=10, batch_size=32, validation_split=0.1)

# Evaluate the model on the test data
model.evaluate(X_test_pad, {'student_star': y_test['student_star'], 'student_difficult': y_test['student_difficult']})

错误: ValueError:发现与任何模型输出都不对应的意外损失或指标:dict_keys(['student_star'])。有效模式输出名称:['student_difficult']。收到的结构是:{'student_star': }.

python machine-learning valueerror
© www.soinside.com 2019 - 2024. All rights reserved.