通过Softmax回归,将logistic的预测二分类的概率的问题推广到了n分类的概率的问题。通过公式
可以看出当月分类的个数变为2时,Softmax回归又退化为logistic回归问题。
下面的几行代码说明一下用法
# -*- coding: utf-8 -*-
import tensorflow as tfA = [1.0,2.0,3.0,4.0,5.0,6.0]with tf.Session() as sess:print sess.run(tf.nn.softmax(A))
输出
[ 0.00426978 0.01160646 0.03154963 0.08576079 0.23312201 0.63369131]
其中所有输出的和为1.