【Python3 SelectKBest 调用personer出现的错误】
初始 相關系數過濾法調用函數
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
總結
以上是生活随笔為你收集整理的【Python3 SelectKBest 调用personer出现的错误】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode(109):有序链表转换
- 下一篇: 【数字信号处理】——Python频谱绘制