gon2

Untitled

Apr 16th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # TRAIN:
  2. n = x_train.shape[0]
  3. ATrain = np.c_[np.ones(n), x_train] # Líkan: f(x_train) = θ_1 + θ_2*x_train
  4.  
  5. theta,res,rank,_ = np.linalg.lstsq(ATrain, y_train, rcond=False)
  6. w = theta[1:]
  7. vTrain = theta[0]
  8. yx = np.dot(x_train, w) + vTrain
  9. ypredTrain = np.sign(yx)
  10. skekkja = np.sum(y_train != ypredTrain)/n
  11. print("Train-skekkja: ", skekkja)
  12.  
  13. # TRAIN:
  14. n = x_test.shape[0]
  15. ATest = np.c_[np.ones(n), x_test] # Líkan: f(x_test) = θ_1 + θ_2*x_test
  16.  
  17. theta,res,rank,_ = np.linalg.lstsq(ATest, y_test, rcond=False)
  18. w = theta[1:]
  19. vTest = theta[0]
  20. yx = np.dot(x_test, w) + vTest
  21. ypredTest = np.sign(yx)
  22. skekkja = np.sum(y_test != ypredTest)/n
  23. print("Test-skekkja: ", skekkja)
Advertisement
Add Comment
Please, Sign In to add comment