Advertisement
Guest User

leastsquares

a guest
Nov 19th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import numpy as np
  2. def leastSquares(data, label):
  3.  
  4. xzeros = np.transpose(np.ones(label.size)[np.newaxis])
  5. print("xzeros ", xzeros)
  6. print("xzeros ", np.transpose(xzeros))
  7. print(label.shape, data.size)
  8. dataaug = np.hstack([xzeros, data])
  9. print("dataaug ", dataaug)
  10. datam = np.linalg.inv(np.matmul(np.transpose(dataaug), dataaug))
  11. print("datam", datam)
  12. datax = np.matmul(datam, np.transpose(dataaug))
  13. print("datax", datax)
  14. weight = np.matmul(label, np.transpose(datax))[1:]
  15. print("weight", weight)
  16. bias = np.matmul(label, np.transpose(datax))[0]
  17. print(bias)
  18.  
  19.  
  20. return weight, bias
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement