# TRAIN: n = x_train.shape[0] ATrain = np.c_[np.ones(n), x_train] # Líkan: f(x_train) = θ_1 + θ_2*x_train theta,res,rank,_ = np.linalg.lstsq(ATrain, y_train, rcond=False) w = theta[1:] vTrain = theta[0] yx = np.dot(x_train, w) + vTrain ypredTrain = np.sign(yx) skekkja = np.sum(y_train != ypredTrain)/n print("Train-skekkja: ", skekkja) # TRAIN: n = x_test.shape[0] ATest = np.c_[np.ones(n), x_test] # Líkan: f(x_test) = θ_1 + θ_2*x_test theta,res,rank,_ = np.linalg.lstsq(ATest, y_test, rcond=False) w = theta[1:] vTest = theta[0] yx = np.dot(x_test, w) + vTest ypredTest = np.sign(yx) skekkja = np.sum(y_test != ypredTest)/n print("Test-skekkja: ", skekkja)