In [ ]:
from numpy import exp, array, random, dot
datum = array([0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1])
label = array([[0, 1, 1, 0]]).T
random.seed(233)
weights = 2 * random.random((3, 1)) - 1 # (-1, 1)
for i in range(1000):
output = 1 / (1 + exp(-(dot(datum, weights)))) # sigmoid
weights += dot(datum.T, (label - output) * output * (1 - output))
print (1 / (1 + exp(-dot(array([1, 0, 0]), weights)))) # try prediction