Answer the question
In order to leave comments, you need to log in
How to get rid of "ValueError: shapes (2,) and (0,) not aligned: 2 (dim 0) != 0 (dim 0)" error?
Error: "ValueError: shapes (2,) and (0,) not aligned: 2 (dim 0) != 0 (dim 0)"
class Perceptron(object):
def __init__(self, eta=0.1, n_lesson=10):
self.eta = eta # Темп обучения
self.n_lesson = n_lesson # Количество уроков
self.w_ = None
self.errors_ = None
def fit(self, X, y):
self.w_ = np.zeros(1 + X.shape[1])
self.errors_ = []
for _ in range(self.n_lesson):
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 predict(self, X):
return np.where(self.net_input(X) >= 0.0, 1, -1)
X = df.iloc[1:101, [0, 2]].values
y = df.iloc[1:101, 4].values
ppn = Perceptron()
ppn.fit(X, y)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question