Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def leastSquares(data, label):
- xzeros = np.transpose(np.ones(label.size)[np.newaxis])
- print("xzeros ", xzeros)
- print("xzeros ", np.transpose(xzeros))
- print(label.shape, data.size)
- dataaug = np.hstack([xzeros, data])
- print("dataaug ", dataaug)
- datam = np.linalg.inv(np.matmul(np.transpose(dataaug), dataaug))
- print("datam", datam)
- datax = np.matmul(datam, np.transpose(dataaug))
- print("datax", datax)
- weight = np.matmul(label, np.transpose(datax))[1:]
- print("weight", weight)
- bias = np.matmul(label, np.transpose(datax))[0]
- print(bias)
- return weight, bias
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement