我写了一个有关线性回归的小程序。但是,有一个我找不到原因的错误。该程序如下:
from sklearn.datasets import load_svmlight_file
from sklearn.model_selection import train_test_split
import numpy as np
X, Y = load_svmlight_file(r"C:\Users\asus\Desktop\data.txt")
trainx,testx=train_test_split(X,shuffle=False)
trainy,testy=train_test_split(Y,shuffle=False)
traverse_trainx=trainx.T
#闭式解
temp1=(traverse_trainx*trainx).I
temp1.I
错误是:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-130-92af132d9e41> in <module>()
8 traverse_trainx=trainx.T
9 #闭式解
---> 10 temp1=(traverse_trainx*trainx).I
11 temp1.I
12
G:\anaconda\lib\site-packages\scipy\sparse\base.py in __getattr__(self, attr)
684 return self.getnnz()
685 else:
--> 686 raise AttributeError(attr + " not found")
687
688 def transpose(self, axes=None, copy=False):
AttributeError: I not found