选择K最佳特征

2024-06-07 22:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从一个大数据帧中找出最好的特性。我能够获取压缩的数据帧值,但无法获取所选功能的名称。 下面是我的代码:

print('Shape of the bigramdf before feature selection:',bigram_df.shape)
if not os.path.isfile('smalldata/bigram_feather_top_100.feather'):
    SelectKBest(score_func=chi2,k=100).fit(bigram_df.iloc[:,:-1],df['class'])
    cols=SelectKBest.get_support(indices=False) # I am getting error here
    selc_k_best_byte_bigram=bigram_df[:,cols]
    selc_k_best_byte_bigram['id']=bigram_df['id']
    selc_k_best_byte_bigram.to_feather('smalldata/bigram_feather_top_100.feather')

    print('Shape of the bigramdf before feature selection:',selc_k_best_byte_bigram.shape)
else:
    selc_k_best_byte_bigram=pd.read_feather('smalldata/bigram_feather_top_100.feather')

我得到以下错误:

TypeError: get_support() missing 1 required positional argument: 'self'

有人能帮我找出为什么我会有这个打字错误吗


Tags: ofthe数据dftopbytebestprint
1条回答
网友
1楼 · 发布于 2024-06-07 22:25:03

我想你需要在一个变量中初始化这个类,然后调用。获取支持。因此,尝试替换:

SelectKBest(score_func=chi2,k=100).fit(bigram_df.iloc[:,:-1],df['class'])

k_best = SelectKBest(score_func=chi2,k=100).fit(bigram_df.iloc[:,:-1],df['class'])
cols = k_best.get_support(indices=False)

相关问题 更多 >

    热门问题