python - 神经网络用一个神经元预测不良

标签 python machine-learning neural-network artificial-intelligence

import math



inp = 0.1
target = 0.3
weight = 0.04
learning_rate = 1
bias = 0


def sigmoid(x):
    return (1/1+(math.e**(-x)))


for count in range(10):
    net = (weight*inp)+(bias*1)
    out = sigmoid(net)
    error_total = 0.5*((target - out)**2)
    print('error',error_total,'|| output',out,'|| weight',weight)
    adjustment = (out - target)*(out)*(1 - out)*(inp)
    weight = weight - (learning_rate*(adjustment))

输出

error 1.4382215499593243 || output 1.9960079893439915 || weight 0.04
error 1.3827597601324302 || output 1.9629851232842885 || weight 0.3771731560625728
error 1.3336445885853887 || output 1.9331837548698485 || weight 0.6915314696982848
error 1.2897634204261337 || output 1.9060905456580794 || weight 0.9861603791287348
error 1.2502583453938265 || output 1.8813022136162503 || weight 1.2635467711722324
error 1.2144557693222424 || output 1.8584965635651831 || weight 1.5257260148874747
error 1.1818184468701014 || output 1.8374124019729394 || weight 1.7743861541249517
error 1.1519119478941984 || output 1.8178352663541577 || weight 2.0109434853536103
error 1.1243806861957226 || output 1.7995870672926748 || weight 2.2365985045783425
error 1.0989304444985601 || output 1.7825184278777517 || weight 2.4523780684160923

在我的神经网络中,我想预测单个输入的单个输出 我尝试将偏差和学习率设置为不同的值,但没有用

权重不断增加,错误率不断下降,但网络无法达到目标输出

最佳答案

你的 sigmoid 定义是错误的。应该是

def sigmoid(x):
    return 1/(1+(math.e**(-x)))

您应该将一除以(一+指数);相反,您将一一相除,然后将指数添加到除法的结果上(显然是 1)。

关于python - 神经网络用一个神经元预测不良,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42787938/

相关文章:

python - 满足列条件后,Pandas 截断 DataFrame

python - 使用 python 从交互式图表中提取数据点?

python - 自定义池化/反池化层的 Tensorflow Reshape 错误

python - Keras `fit_generator` 验证准确度低,但 `fit` 验证准确度低

python - 在给定简单行向量的循环内创建并命名矩阵

tensorflow - 无法使用tensorflow 2.0.0 beta1保存模型

python tkinter Radiobuttons - 两个按钮在显示之前都被选中

python - 使用阈值级别 pandas 过滤数据帧

python - XOR 的 Tensorflow 在 500 个时期后无法正确预测

tensorflow - 为什么不将 L2 正则化添加回原始损失函数?