V
V
Valentin Birulya2022-02-11 22:35:18
numpy
Valentin Birulya, 2022-02-11 22:35:18

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)


This is not the first time I encounter this error, there is some kind of universal solution, but this time reshape did not help ... But I don’t know how to fix it without reshape :( everything

happens on irises (-1, 1) didn't help:
6206b9a7e9010129328606.png
6206b9707d18a347370568.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question