目标数组的形状为(15000, 250),而输出形状为(None, 1),在使用二元交叉熵损失函数时出现了问题。我该怎么办?

我已经创建了一个模型,但由于目标数组的形状和输出形状不匹配,无法运行。我只是想训练它,但不确定如何解决这个错误。

错误信息:

---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-9-4c7f3cb9ee70> in <module>()     44 y_train = train_data[10000:]     45 ---> 46 fitModel = model.fit(x_train, y_train, epochs=5, batch_size=512, validation_data=(x_val, y_val), verbose=1)     47      48 result = model.evaluate(test_data, test_labels)3 frames/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_utils.py in check_loss_and_target_compatibility(targets, loss_fns, output_shapes)    739           raise ValueError('A target array with shape ' + str(y.shape) +    740                            ' was passed for an output of shape ' + str(shape) +--> 741                            ' while using as loss `' + loss_name + '`. '    742                            'This loss expects targets to have the same shape '    743                            'as the output.')ValueError: A target array with shape (15000, 250) was passed for an output of shape (None, 1) while using as loss `binary_crossentropy`. This loss expects targets to have the same shape as the output.

我应该得到准确率和执行时间的输出。我尝试更改输出层的数值,但对我来说完全不起作用。

我的代码:


回答:

更改

y_val = train_data[:10000]y_train = train_data[10000:]

y_val = train_labels[:10000]y_train = train_labels[10000:]

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注