In [6]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.html.widgets import interact
from sklearn.datasets import load_digits
digits = load_digits()
print(digits.data.shape)
In [ ]:
weights = np.random.randn(65)
inputs = digits.data[0:1200]
answers = digits.target
lc = 0.02
In [10]:
class Perceptron(object):
def __init__(self, inputs, answers, weights, lc):
self.inputs = inputs
aelf.answers = answers
self.weights = weights
self.lc = lc
def activate(self, sum_):
if sum_ > 0:
return 1
else:
return -1
def sum_(self, inputs):
sum_ = 0
for n in range(len(weights)):
sum_ += inputs[n]*weights[n]
return activate(sum_)
def train(self, inputs, answer):
guess = sum_(inputs)
error = answer - guess
for n in range(len(weights)):
weights[n] += lc*error*inputs[n]
In [ ]:
def sigmoid(z):
return 1/(1 + exp(-z))
def sig_prime(z):
return sigmoid(z) * (1 - sigmoid(z))