python - Keras假形,

标签 python python-3.x machine-learning keras neural-network

嗨,有人了解 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_categorical
y_binary = to_categorical(y_int)


Alternatively, you can use the loss function ` 
sparse_categorical_crossentropy` instead, which does expect integer targets.

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

最佳答案

categorical_crossentropy更改为binary_crossentropy

第 83 行设置:

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

关于python - Keras假形,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53702456/

相关文章:

python - Python 3 中的 super() 怪异之处

适合初学者的 Python 套接字/中断

python - 如何在python中获取两个数字(未知数字长度)之间的子字符串

python - 在 FTPS 服务器上使用 ftplib 列出目录时 sslobj.do_handshake 中的 "OSError: [Errno 0] Error"

python - 如何创建整数列表的二维列表并设置特定值

python - Pytorch 运行时错误 : size mismatch, m1 : [1 x 7744], m2:[400 x 120]

python - 如何优化大型数据集的标签编码(sci-kit learn)

r - 如何解释该分类 TreeMap 中的预测?

python - 用户输入列表,然后将数字相加计算ISBN校验位

python - 如何在 Flask 中运行 localhost