初始 相关系数过滤法调用函数 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