HITOMIi23

Untitled

Feb 24th, 2019
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. def F(data,beta,lam = 0):
  2.     n = data.count() # find the number of (x,y) pairs in data
  3.     regMSE = (data.map(lambda (x,y): f(x, y, beta)).reduce(lambda x, y: x+y))/float(n) + lam*sum(beta**2)
  4.     return regMSE
  5.  
  6. def test(data,beta):
  7.     m = data.count()  # find the number of (x,y) pairs in testing data
  8.     testMSE = (data.map(lambda (x,y): f(x,y,beta)).reduce(lambda x, y: x+y))/float(m)
  9.     return testMSE
Advertisement
Add Comment
Please, Sign In to add comment