相关疑难解决方法(0)

在Scikit功能选择后保留功能名称

在从一组数据上运行Scikit-Learn的方差阈值后,它会删除一些功能.我觉得我在做一些简单而又愚蠢的事情,但我想保留其余功能的名称.以下代码:

def VarianceThreshold_selector(data):
    selector = VarianceThreshold(.5) 
    selector.fit(data)
    selector = (pd.DataFrame(selector.transform(data)))
    return selector
x = VarianceThreshold_selector(data)
print(x)
Run Code Online (Sandbox Code Playgroud)

更改以下数据(这只是行的一小部分):

Survived    Pclass  Sex Age SibSp   Parch   Nonsense
0             3      1  22   1        0        0
1             1      2  38   1        0        0
1             3      2  26   0        0        0
Run Code Online (Sandbox Code Playgroud)

进入这个(再次只是行的一小部分)

     0         1      2     3
0    3      22.0      1     0
1    1      38.0      1     0
2    3      26.0      0     0
Run Code Online (Sandbox Code Playgroud)

使用get_support方法,我知道这些是Pclass,Age,Sibsp和Parch,所以我宁愿返回更像:

     Pclass         Age      Sibsp     Parch
0        3          22.0         1         0
1        1          38.0         1         0 …
Run Code Online (Sandbox Code Playgroud)

python feature-selection pandas scikit-learn output

12
推荐指数
3
解决办法
9189
查看次数

标签 统计

feature-selection ×1

output ×1

pandas ×1

python ×1

scikit-learn ×1