Introduction to Deep Learning in Python
Dan Becker
Data Scientist and contributor to Keras and TensorFlow libraries
2 * -4 * 3
-24
0.01
, the new weight would be2 - 0.01(-24) = 2.24
import numpy as np weights = np.array([1, 2]) input_data = np.array([3, 4]) target = 6 learning_rate = 0.01 preds = (weights * input_data).sum() error = preds - target
print(error)
5
gradient = 2 * input_data * error
gradient
array([30, 40])
weights_updated = weights - learning_rate * gradient preds_updated = (weights_updated * input_data).sum() error_updated = preds_updated - target
print(error_updated)
2.5
Introduction to Deep Learning in Python