初始 相關系數過濾法調用函數
from sklearn.feature_selection import SelectKBest
from scipy.stats import pearsonr
SelectKBest(lambda X,Y:np.array(map(lambda x:pearsonr(x,Y),X.T)).T,k=2)
.fit_transform(X_test,y_test)
TypeError: float() argument must be a string or a number, not ‘map’
原因:
python3下的map()函數返回類型為iterators,不再是list,所以將map語句修改為:x = list(map())
修改:
SelectKBest(lambda X,Y:np.array(list(map(lambda x:pearsonr(x,Y),X.T))).T,k=2)
.fit_transform(X_test,y_test)
IndexError: index 32 is out of bounds for axis 0 with size 2
翻譯:
IndexError:索引32超出軸0的大小為2的范圍
修改:
SelectKBest(lambda X,Y:np.array(list(map(lambda x:pearsonr(x,Y),X.T))).T[0],k=2)
.fit_transform(X_test,y_test)
————————————————
原文鏈接:https://blog.csdn.net/qq_31269555/article/details/88389089