我试过这个并且工作正常:
phi = np.zeros((len(traindata),3))
phi[:,0] = 1
phi[:,1] = traindata[:,0]
phi[:,2] = traindata[:,1]
Wml = np.dot(np.dot((np.linalg.pinv(np.dot((phi.T),phi))),(phi.T)), y_train)
print Wml, "weight selection"
[[ -1.08778441e+01]
[ -3.61672723e-02]
[ -4.38518378e-03]] weight selection
但是当我尝试使用更多列时,如下所示:
phi = np.zeros((len(traindata),5))
phi[:,0] = 1
phi[:,1] = traindata[:,0]
phi[:,2] = traindata[:,1]
phi[:,3] = traindata[:,2]
phi[:,4] = traindata[:,3]
Wml = np.dot(np.dot((np.linalg.pinv(np.dot((phi.T),phi))),(phi.T)), y_train)
print Wml, "weight selection"
我没有获得任何结果或错误。我错过了什么或者我做错了什么?我尝试过不同的数据集和不同的大小,它似乎工作正常,直到3列,但从4列没有显示。
提前感谢您的帮助!