Programming, Data Science, Machine Learning, Python.
get_label(self, y): y_ = np.where(y<=0, -1, 1) return y_ # Fit function to train from data using gradient descent def fit(self, X, y): self.initialize_weights(X) labels = self.get_label(y) for _ in range(self.n_iter): for idx, xi in enumerate(X): condition = labels[idx]*(np.dot(xi,self.w) + self.b)