为了账号安全,请及时绑定邮箱和手机立即绑定

如何提高前馈神经网络的准确性?

如何提高前馈神经网络的准确性?

慕田峪4524236 2022-06-07 18:57:03
我在提高用 python 编码的前馈神经网络的准确性方面遇到问题。我不确定这是一个真正的错误还是只是我的数学函数的无能,但我得到的输出模棱两可(如 0.5)无论我增加多少迭代......我的代码: -from numpy import exp, array, random, dotclass NeuralNetwork():    def __init__(self):        random.seed(1)        self.synaptic_weights = 2 * random.random((3, 1)) - 1     # MM reuslt = 3 (3 * 1)    def Sigmoid(self, x):        return 1 / (1 + exp(-x))    def Sigmoid_Derivative(self, x):        return x * (1 - x)    def train(self, Training_inputs, Training_outputs, iterations):        output = self.think(Training_inputs)        print ("THe outputs are: -", output)        erorr = Training_outputs - output        adjustment = dot(Training_inputs.T, erorr * self.Sigmoid_Derivative(output))        print ("The adjustments are:-", adjustment)        self.synaptic_weights += output    def think(self, inputs):        Training_inputs = array(inputs)        return self.Sigmoid(dot(inputs, self.synaptic_weights))# phew! the class ends..if __name__ == "__main__":    neural_network = NeuralNetwork()    print("Random startin weights", neural_network.synaptic_weights)    Training_inputs = array([[1, 1, 1],                              [0, 0, 0],                              [1, 0, 1],])                 # 3 rows * 3 columns???    Training_outputs = array([[1, 1, 0]]).T    neural_network.train(Training_inputs, Training_outputs, 0)    print ("New synaptic weights after training: ")    print (neural_network.synaptic_weights)    # Test the neural network with a new situation.    print ("Considering new situation [1, 0, 0] -> ?: ")    print (neural_network.think(array([1, 0, 0])))虽然这些是我的输出:=>[Running] python -u "/home/neel/Documents/VS-Code_Projects/Machine_Lrn(PY)/test.py"Random startin weights [[-0.16595599] [ 0.44064899] [-0.99977125]]THe outputs are: - [[0.3262757 ] [0.5       ] [0.23762817]]我尝试过更改迭代,但差异非常小。我认为问题可能出在我的一个数学(Sigmoid)函数中。除此之外,我认为第 20 行的点乘法可能是个问题,因为调整对我来说看起来很奇怪......另外,0.5 不是表示我的网络没有学习,因为它只是随机猜测吗?PS:-我认为我的问题不是重复的,因为它涉及所述模型的“准确性”,而链接的问题涉及“不需要的输出”
查看完整描述

1 回答

?
倚天杖

TA贡献1828条经验 获得超3个赞

您的Sigmoid_Derivative功能是错误的,在您的上一个问题中已经指出了这一点;它应该是:

def Sigmoid_Derivative(self, x):
    return self.Sigmoid(x) * (1-self.Sigmoid(x))

请参阅Math.SE上的 sigmoid 函数线程的导数,以及此处的讨论。

如果更正此问题仍然没有给出预期的结果,请不要更改上面的问题 - 相反,打开一个新问题...


查看完整回答
反对 回复 2022-06-07
  • 1 回答
  • 0 关注
  • 119 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号