Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何知道使用SelectKBest选择了哪些功能?_Python_Machine Learning_Scikit Learn_Feature Extraction_Feature Selection - Fatal编程技术网

Python 如何知道使用SelectKBest选择了哪些功能?

Python 如何知道使用SelectKBest选择了哪些功能?,python,machine-learning,scikit-learn,feature-extraction,feature-selection,Python,Machine Learning,Scikit Learn,Feature Extraction,Feature Selection,一些功能在运行SelectKBest后被选中,结果作为数组返回,因此我不知道它们是哪些功能,因为我的培训集有数千个功能。 我想在我的测试集中找到并挑选这些特性,然后删除其余的。有什么方便的方法吗?谢谢 代码如下: from sklearn.feature_selection import SelectKBest, f_regression X_opt=SelectKBest(f_regression,k=2000) X_new=X_opt.fit_transform(df_train_X_mm,

一些功能在运行SelectKBest后被选中,结果作为数组返回,因此我不知道它们是哪些功能,因为我的培训集有数千个功能。 我想在我的测试集中找到并挑选这些特性,然后删除其余的。有什么方便的方法吗?谢谢

代码如下:

from sklearn.feature_selection import SelectKBest, f_regression
X_opt=SelectKBest(f_regression,k=2000)
X_new=X_opt.fit_transform(df_train_X_mm, train_y)
X_new`
结果是:

array([[0.        , 0.        , 0.        , ..., 0.        , 0.        ,
    0.        ],
   [0.        , 0.        , 0.00688335, ..., 0.        , 0.        ,
    0.        ],
   [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
    0.        ],
   ...,
   [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
    0.        ],
   [0.        , 0.        , 0.        , ..., 0.        , 0.        ,
    0.        ],
   [0.        , 0.        , 0.06257587, ..., 0.        , 0.        ,
    0.        ]])

您需要的是
get\u support
功能选择方法。选择kbest。它返回一个布尔数组,表示是否选择了给定功能(
True
)或(
False
)。

您要查找的是
功能选择的
get\u support
方法。选择kbest
。它返回一个布尔数组,表示是否选择了给定的功能(
True
)或(
False
)。

是否共享返回数组的代码?是否共享返回数组的代码?