如何在python中找到分类神经网络的预测输出?
我是python和学习神经网络的新手。我有一个经过训练的三层前馈神经网络,隐层有2个神经元,输出层有3个神经元。我想知道如何计算输出层值/预测输出 我从网络中提取权重和偏差,并计算隐藏层的激活值。我只是想确认如何使用如何在python中找到分类神经网络的预测输出?,python,neural-network,softmax,Python,Neural Network,Softmax,我是python和学习神经网络的新手。我有一个经过训练的三层前馈神经网络,隐层有2个神经元,输出层有3个神经元。我想知道如何计算输出层值/预测输出 我从网络中提取权重和偏差,并计算隐藏层的激活值。我只是想确认如何使用softmax函数来计算输出层神经元的输出 我的执行情况如下: weights_from_hiddenLayer_to_OutputLayer = [ [x, y], # two weights connected to the output neuron 1 from h
softmax
函数来计算输出层神经元的输出
我的执行情况如下:
weights_from_hiddenLayer_to_OutputLayer = [
[x, y], # two weights connected to the output neuron 1 from hidden neurons 1 and 2
[a, b], # two weights connected to the output neuron 2 from hidden neurons 1 and 2
[c, d] # two weights connected to the output neuron 3 from hidden neurons 1 and 2I
]
# output layer biases extracted from the neural network
biases_output_layer = [a, b, c]
act1 = m # activation value of hidden neuron 1
act2 = n # activation value of hidden neuron 2
arr = []
for i, weights in enumerate(weights_from_hiddenLayer_to_OutputLayer):
arr.append(m*weights[0]+n*weights[1] +
biases_output_layer[i])
# i believe this will be the brightest neuron / predicted neural networks output ?
print(np.argmax(arr))
我在互联网上搜索了python中的
softmax
,现在我已经找到了。我的预测结果与神经网络预测结果基本不同。然而,我使用的是来自同一个训练模型的完全相同的值。您的输出将是从\u hiddenLayer\u到\u OutputLayer的权重\u与之前激活的矩阵相乘。
然后,您可以将其传递给softmax函数以获得概率分布,并根据猜测使用argmax
,以获得相应的类
weights_from_hiddenLayer_to_OutputLayer = np.array([
[x, y], # two weights connected to the output neuron 1 from hidden neurons 1 and 2
[a, b], # two weights connected to the output neuron 2 from hidden neurons 1 and 2
[c, d] # two weights connected to the output neuron 3 from hidden neurons 1 and 2I
])
act = np.array([m, n])
biases_output_layer = [a, b, c]
arr = np.dot(weights_from_hiddenLayer_to_OutputLayer, act) # matrix multiplication of weights and activations
arr = arr + biases_output_layer
probability = np.exp(arr) / np.sum(np.exp(arr), axis=0) # softmax
print(np.argmax(probability))
请注意,从技术上讲,您不需要使用softmax,除非您正在反向传播或尝试评估作为np.argmax()结果的输出的可信度无论您是通过arr
还是相应的probability
都将是相同的,不会在任何地方添加偏差?对不起,我错过了您的偏差列表。我更新了我原来的帖子