【问题标题】:Could not understand the output of this neural network无法理解这个神经网络的输出
【发布时间】:2021-12-30 10:05:29
【问题描述】:

我给出了一个输入数组 (3000,1),我期望的输出是 0,1,2 的多重概率。 我已经在 0 和 1 之间缩放了我的输入,那么为什么我的输出会超过 1,以及那些连字符的数字是什么。

在此处输入代码

training_input, training_label = shuffle(training_input, training_label)

# training_input range from 1-100 so we scale it down to between 0-1
scaler = MinMaxScaler(feature_range=(0, 1))
scaled_training_input = scaler.fit_transform(training_input.reshape(-1, 1))

model = tf.keras.models.Sequential()

model.add(tf.keras.layers.Dense(16, input_shape=(1,), activation='relu'))
model.add(tf.keras.layers.Dense(32, activation='relu'))
model.add(tf.keras.layers.Dense(3, activation='softmax'))
[enter image description here][1]


  [1]: https://i.stack.imgur.com/OXEmG.png

【问题讨论】:

    标签: python keras deep-learning neural-network


    【解决方案1】:

    输出数组的元素是实例分别属于0、1和2类的概率

    要做出预测,您必须选择具有最高概率的类。

    连字符代表负幂,即 9.99e-01 是 0.999
    因此,所有的数字都小于一并且它们的和是一。

    四舍五入:

    import numpy as np
    pred = (np.random.rand(27) ** 5).reshape(-1,3) #sample output
    np.round(pred, 2) #rounds to show only a few decimals
    

    【讨论】:

    • 你能告诉我如何去除那些负面力量,并把它们显示为 0.999 而不是他们的负面力量,因为我之前用过 2 个类的代码,它没有显示负面力量,但只有0.95等类的概率
    • 感谢您的帮助!!!
    • 不客气,很高兴你发现它有用!
    【解决方案2】:

    激活函数softmax是指数形式的。所以你的输出会超过1。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    • Softmax 激活将为输出层中的每个节点输出一个值。输出值分别表示实例属于这些类中的每一个的概率,并且这些值总和为 1.0。 softmax(Z1) = exp(Z1) / [exp(Z1) + exp(Z2) + exp(Z3)]。因此,softmax 函数总是小于(或等于)1。
    猜你喜欢
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 2018-11-26
    • 2019-01-30
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    相关资源
    最近更新 更多