使用卡方测试选择最佳的K功能

发布于 2025-02-10 12:07:27 字数 413 浏览 1 评论 0原文

我一直在尝试实现卡方功能选择,其中我选择了最佳的K功能或高度依赖于label的功能。

到目前为止,我正在这样做:

from scipy.stats import chi2_contingency

for col in all_cols:
    contingency_table = pd.crosstab(data[col] , y)
    stat, _, _ , _ = chi2_contingency(contingency_table.values)

然后,我选择了具有较高Stat值的顶部功能。 由于Sklearn已经使用selectkbest(CHI2,...)提供了此功能。 那么,我的实施是正确的还是与预建方法同步的?

I have been trying to implement Chi-Square feature selection, wherein I select the best k features or the features that are highly dependent to the Label.

So far I am doing this:

from scipy.stats import chi2_contingency

for col in all_cols:
    contingency_table = pd.crosstab(data[col] , y)
    stat, _, _ , _ = chi2_contingency(contingency_table.values)

Then I am selecting the top features as the ones having higher stat values.
Since sklearn already provides this feature using SelectKBest(chi2,...).
So, is my implementation correct or in sync with the pre-built approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文