Python 根据scikit学习中的最低分数选择功能

Python 根据scikit学习中的最低分数选择功能,python,scikit-learn,feature-selection,Python,Scikit Learn,Feature Selection,我正在尝试在管道中选择功能。 我的管道如下: 我在考虑使用 具有可配置策略的单变量特征选择器 从文件中: class sklearn.feature_selection.GenericUnivariateSelect(score_func=<function f_classif>, mode=’percentile’, param=1e-05) score_func : callable Function taking two arrays X and y, and

我正在尝试在管道中选择功能。 我的管道如下:

我在考虑使用

具有可配置策略的单变量特征选择器

从文件中:

class sklearn.feature_selection.GenericUnivariateSelect(score_func=<function f_classif>, mode=’percentile’, param=1e-05)

   score_func : callable

    Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). For modes ‘percentile’ or ‘kbest’ it can return a single array scores.
但如何添加其他模式? 可能,无需重写SelectorMixin之上的类


编辑 我的管线看起来像:

from  sklearn.feature_selection import GenericUnivariateSelect

custom_filter=GenericUnivariateSelect(my_score)   
MyProcessingPipeline=Pipeline(steps=[('filter_step', custom_filter)])
我的处理管道非常简单:

X=pd.DataFrame(data=np.random.rand(500,3))
MyProcessingPipeline.fit(X)
MyProcessingPipeline.transform(X)
我在这方面的得分是:

#Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). 
def my_score(X,y):
    return (np.random.rand(X.shape[1]),np.zeros((X.shape[1],1)))
在我的例子中,我希望转换保留所有的特性,
my_score
为这些特性返回一个分数
>0.6
。 如何获得?
我越来越确信我将不得不重写一些本地的sklearn类,但是,有没有人知道我应该覆盖哪一个,以最大限度地减少要编写的代码量,同时能够执行这个非常简单的功能选择?

您应该为您的问题添加更具体的内容,并添加完整的代码。我想现在我已经添加了所有需要的详细信息。我无法向您发送完整的源代码,我希望您能够理解。您应该为您的问题添加更多的细节,例如您到底想做什么,并添加完整的代码。我想现在我已经添加了所有需要的详细信息。我不能给你发送完整的源代码,希望你能理解
#Function taking two arrays X and y, and returning a pair of arrays (scores, pvalues). 
def my_score(X,y):
    return (np.random.rand(X.shape[1]),np.zeros((X.shape[1],1)))