TVP

# 如何在 Scratch 中用 Python 构建神经网络

https://towardsdatascience.com/how-to-build-your-own-neural-network-from-scratch-in-python-68998a08e4f6

2 层神经网络的结构

class NeuralNetwork:

def __init__(self, x, y):

self.input = x

self.y = y

self.output = np.zeros(y.shape)

classNeuralNetwork:

def__init__(self, x, y):

self.input = x

self.weights1 = np.random.rand(self.input.shape[1],4)

self.weights2 = np.random.rand(4,1)

self.y = y

self.output = np.zeros(self.y.shape)

deffeedforward(self):

self.layer1 = sigmoid(np.dot(self.input,self.weights1))

self.output = sigmoid(np.dot(self.layer1,self.weights2))

defbackprop(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

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180626A07DU900?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2018-06-21

2018-06-14

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08

2022-12-08