【问题标题】:How to convert numpy ndarray values to probability values如何将 numpy ndarray 值转换为概率值
【发布时间】:2017-03-17 09:19:50
【问题描述】:

以下结果是线性回归[y = Wx + b]的numpy ndarray分数。

scores = tf.nn.xw_plus_b(self.h_drop, W, b, name='scores')
~ ~ .....
all_scores = np.zeros(shape=(0,len(label_dict))) 
~~...    
all_scores = np.concatenate((all_scores, batch_scores) , axis=0) 

如何将上面的 numpy ndarray 值更改为 ndarray 概率值?

想要的结果:

      col0    col1      col2     col3   col4    col5 

Row1 0.02  |   0.123 | 0.678 | 0.067 | 0.0987 | 0.1089   : Sum(col0~5) = 1 
~ 

【问题讨论】:

  • 什么概率?
  • 我想将结果值的每个值转换为概率值,例如上面的“期望结果”[all_scores:ndarray values]。

标签: python python-3.x numpy tensorflow


【解决方案1】:

最简单的方法是应用于softmax函数:

f(x) = e^x_i / sum_j e^x_j

这会将任何范围内的值转换为总和为 1 的向量,可以将其解释为概率。执行此操作的 TF 函数是 tf.nn.softmax。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-17
    • 2020-06-27
    • 2023-01-18
    • 2017-12-14
    • 2015-08-07
    • 1970-01-01
    相关资源
    最近更新 更多