Keras 错误形状,

大家好,有人对Keras很熟悉吗?我不明白问题出在哪里?我遇到了这个问题:

ValueError: You are passing a target array of shape (1000, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via...from keras.utils import to_categoricaly_binary = to_categorical(y_int)Alternatively, you can use the loss function ` sparse_categorical_crossentropy` instead, which does expect integer targets.

这是完整的代码:https://ideone.com/v9yojt


回答:

categorical_crossentropy更改为binary_crossentropy

在第83行设置:

model.compile(loss='binary_crossentropy', optimizer="sgd", metrics=['accuracy'])

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中创建了一个多类分类项目。该项目可以对…

发表回复

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