简体   繁体   中英

Problem with python script - invalid syntax

The following code that I pulled from here in an effort to better understand how Machine Learning and Neural Networks work, isn't working. It keeps producing an "invalid syntax" error at line 31:

self.weights1 += d_weights1

Here is the function that fails:

    def backprop(self):
        # application of the chain rule to find derivative of the loss function with respect to weights2 and weights1
        d_weights2 = np.dot(self.layer1.T, (2*(self.y - self.output) * sigmoid_derivative(self.output)))
        d_weights1 = np.dot(self.input.T, (np.dot(2*(self.y - self.output) * sigmoid_derivative(self.output), self.weights2.T) * sigmoid_derivative(self.layer1))

        # update the weights with the derivative (slope) of the loss function        
        self.weights1 += d_weights1
        self.weights2 += d_weights2

You have forgotten to put a brackets at the end of line 4

d_weights1 = np.dot(self.input.T, (np.dot(2*(self.y - self.output) * sigmoid_derivative(self.output), self.weights2.T) * sigmoid_derivative(self.layer1))

Here is the correction:

d_weights1 = np.dot(self.input.T, (np.dot(2*(self.y - self.output) * sigmoid_derivative(self.output), self.weights2.T) * sigmoid_derivative(self.layer1)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM