SHARE
TWEET

leastsquares

a guest Nov 19th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top