def export_best_feature_names(self, df, labels, out_folder_path, k):
columns, repos, observations = self.decompose_df(df)
feature_scores = SelectKBest(chi2, k=k).fit(observations, labels).scores_
feature_scores = np.nan_to_num(feature_scores)
k_best_features = np.argpartition(feature_scores.ravel(), (-1) * k)[(-1) * k:]
k_best_feature_names = columns[k_best_features]
out_file_path = os.path.join(out_folder_path, "feature_selection.txt")
with open(out_file_path, "w") as output_file:
for feature_name in k_best_feature_names:
output_file.write(feature_name + "\n")
analysis_utilities.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录