关于python损失函数代码的信息(13)


self.loss = tf.reduce_mean(tf.reduce_sum(tf.square((self.label_layer - self.output_layer)), reduction_indices=[1]))
self.optimizer = tf.train.GradientDescentOptimizer(learn_rate).minimize(self.loss)
initer = tf.initialize_all_variables()#做训练
self.session.run(initer)for i in range(limit):
self.session.run(self.optimizer, feed_dict={self.input_layer: cases, self.label_layer: labels})def predict(self, case):
return self.session.run(self.output_layer, feed_dict={self.input_layer: case})def test(self):
x_data = https://www.04ip.com/post/np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_data = https://www.04ip.com/post/np.array([[0, 1, 1, 0]]).transpose()
test_data = https://www.04ip.com/post/np.array([[0, 1]])
self.setup(2, [10, 5], 1)
self.train(x_data, y_data)
print(self.predict(test_data))
nn = BPNeuralNetwork()
nn.test()12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
关于python损失函数代码和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读