錯誤代碼:
from scipy import stats for i in range(x.shape[1]): pea = stats.pearsonr(x[:,i],y) #輸出每個特征對因變量的影響 print(pea) pea
errer:
'(slice(None, None, None), 0)' is an invalid key
修改:
x = np.array(x,type(float)) y = np.array(y,type(float)) from scipy import stats for i in range(x.shape[1]): pea = stats.pearsonr(x[:,i],y) #輸出每個特征對因變量的影響 print(pea) pea
就可以了