在 Scikit Learn 中运行 SelectKBest 后出现“numpy.ndarray”对象没有属性“get_support”错误消息

Jef*_*eng 4 feature-extraction scikit-learn

我遇到了一个与这个旧问题相关的问题:在 Scikit Learn 中运行 SelectKBest 后获取功能名称的最简单方法

当尝试使用“get_support()”获取所选功能时,我收到错误消息:

numpy.ndarray'对象没有属性'get_support

我将非常感谢您的帮助!

杰夫

Viv*_*mar 6

如果不进行适配,您就无法获得支持。您需要进行拟合,以便选择器可以分析数据,然后调用get_support()选择器,而不是输出fit_transform()

目前你正在做类似的事情:

selector = SelectKBest()

#fit_transform returns the data after selecting the best features
new_data = selector.fit_transform(old_data, labels)

#so you are trying to access get_support() on new data, which is not possible
new_data.get_support()
Run Code Online (Sandbox Code Playgroud)

致电fit()或后fit_transform(),执行以下操作:

# get_support is a method of SelectKBest class
selector.get_support()
Run Code Online (Sandbox Code Playgroud)