I have just begun learning Machine Learning using Python. I have written the following class which gives an error:
TypeError: can't multiply sequence by non-int of type 'float'
class Perceptron(object):
def __init__(self, eta=0.01, n_iter=10):
self.eta = eta # Learning Rate
self.n_iter = n_iter # Number of iteration over the training dataset
def fit(self, x, y):
self.w_ = np.zeros(1 + x.shape[1]) # Initialize Weights to zero initially # x = {array-like} : shape[no_of_samples, no_of_features]
self.errors_ = [] # No errors in the beginning of the computation
for _ in range(self.n_iter):
errors = 0
for xi, target in zip(x, y):
update = self.eta * (target - self.predict(xi))
self.w_[1:] += update * xi
self.w_[0] += update
errors += int(update != 0.0)
self.errors_.append(errors)
return self
def net_input(self, x):
return np.dot(x, self.w_[1:]) + self.w_[0]
def predict(self, x):
return np.where(self.net_input(x) >= 0.0, 1, -1)
I am getting an error in the net_input() method at np.dot(). I am using the following dataset : https://raw.githubusercontent.com/uiuc-cse/data-fa14/gh-pages/data/iris.csv