Understanding neural networks by building one.
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
X = np.array([[0,0], [0,1], [1,0], [1,1]])
y = np.array([[0], [1], [1], [0]])
weights = np.random.random((2, 1))
for _ in range(10000):
output = sigmoid(np.dot(X, weights))
error = y - output
weights += np.dot(X.T, error * output * (1 - output))