独热码

独热编码

tf.one_hot(待转换数据,depth=及分类)

1
2
3
4
classes = 3
labels = tf.constant([1,0,2]) # 输入元素最小为0,最大为2
output=tf.one_hot(labels,depth=classes)
ptint(output())

独热码转符合概率分布

公式:

Softmax(yi)=eyiΣj=0neyi\mathrm{Softmax}(y_i)=\frac{\mathrm{e}^{y_i}}{\Sigma_{j=0}^n\mathrm{e}^{y_i}}