我使用keras中提供的to_categorical函数将类型为float的numpy ndarray转换为二进制对应项。Y的维数为2144x1,而函数返回的数组的维数为2144x2。如何从to_categorical获得2144x1数组?Y只包含0和1s (浮点类型)函数调用:
y_binary = to_categorical(Y)发布于 2018-02-06 03:13:49
keras.utils.to_categorical(y, num_classes=None)
将类向量(整数)转换为二进制类矩阵。
但是它看起来不支持浮动(它为所有的数字做地板)
to_categorical([0, 0.1, 0.2, 0.3, 1])
[[ 1. 0.]
[ 1. 0.]
[ 1. 0.]
[ 1. 0.]
[ 0. 1.]]
to_categorical([0, 1, 2, 3, 1])
[[ 1. 0. 0. 0.]
[ 0. 1. 0. 0.]
[ 0. 0. 1. 0.]
[ 0. 0. 0. 1.]
[ 0. 1. 0. 0.]]一种解决方案是,将其扩展到正整数并转换为范畴。
https://stackoverflow.com/questions/44749268
复制相似问题