In [1]:
import numpy as np

In [10]:
#https://blog.dbrgn.ch/2013/3/26/perceptrons-in-python/

function = lambda x: x**2

training_data = [
    (np.array([1, 1]), 1),
    (np.array([2, 1]), 4),
    (np.array([3, 1]), 9),
    (np.array([9, 1]), 81),
    (np.array([-2, 1]), 4),
    (np.array([-6, 1]), 36),
]

weights = np.random.rand(2)
errors = []
eta = 0.3
n = 10

for i in range(n):
    inputs = [i[0] for i in training_data]
    print(inputs)
    
    x, expected = np.random.choice(inputs)
    result = np.dot(weights, x)
    error = expected - unit_step(result)
    errors.append(error)
    w += eta * error * x
    
for x, _ in training_data:
    result = dot(x, weights)
    print(result, function(result))


[array([1, 1]), array([2, 1]), array([3, 1]), array([9, 1]), array([-2,  1]), array([-6,  1])]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-c5f301edd26a> in <module>()
     20     inputs = [i[0] for i in training_data]
     21     print(inputs)
---> 22     x, expected = np.random.choice(inputs)
     23     result = np.dot(weights, x)
     24     error = expected - unit_step(result)

mtrand.pyx in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:10351)()

ValueError: a must be 1-dimensional

In [ ]:


In [ ]: