[英]Selecting K Best Features
I was trying to find out the best features from a large dataframe.我试图从大型数据框中找出最佳功能。 I am able to get the compressed dataframe values but I couldn't get the names of the features that were selected.我能够获得压缩的数据帧值,但无法获得所选功能的名称。 Below is my code:下面是我的代码:
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')
I am getting the following error:我收到以下错误:
TypeError: get_support() missing 1 required positional argument: 'self'
Can some one help me in finding why I am getting this TypeError.有人能帮我找出为什么我会收到这个 TypeError 吗?
I think you need to initialise the class in a variable and then call .get_support.我认为您需要在变量中初始化类,然后调用 .get_support。 So try to replace:所以尝试替换:
SelectKBest(score_func=chi2,k=100).fit(bigram_df.iloc[:,:-1],df['class'])
with和
k_best = SelectKBest(score_func=chi2,k=100).fit(bigram_df.iloc[:,:-1],df['class'])
cols = k_best.get_support(indices=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.