【问题标题】:Using chi-squared test for feature selection使用卡方检验进行特征选择
【发布时间】:2014-02-05 04:07:50
【问题描述】:

我总是难以理解卡方检验的重要性以及如何将其用于特征选择。我尝试阅读 wiki 页面,但没有得到实际的理解。谁能解释一下?

【问题讨论】:

  • 你了解卡方检验吗?对于特征选择,它正在寻找与由特征分布不依赖于类别的零假设预测的观察结果的偏差。
  • 你应该尝试在stats.stackexchange.com 询问它

标签: machine-learning feature-selection chi-squared


【解决方案1】:

卡方检验通过确定特征变量与目标变量之间的相关性,帮助您确定可用特征列表中最重要的特征。

以下示例取自https://chrisalbon.com/machine-learning/chi-squared_for_feature_selection.html

下面的测试将在最初的 4 个可用特征中选择两个最佳特征(因为我们将 2 分配给“k”参数)。

# Load libraries
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2

# Load iris data
iris = load_iris()

# Create features and target
X = iris.data
y = iris.target

# Convert to categorical data by converting data to integers
X = X.astype(int)

# Select two features with highest chi-squared statistics
chi2_selector = SelectKBest(chi2, k=2)
X_kbest = chi2_selector.fit_transform(X, y)
type(X_kbest)

# Show results
print('Original number of features:', X.shape[1])
print('Reduced number of features:', X_kbest.shape[1])

【讨论】:

    【解决方案2】:

    卡方特征选择是一种用于分类变量的单变量特征选择技术。也可以用于连续变量,但需要先对连续变量进行分类。

    它是如何工作的?

    它通过基于列联表计算卡方统计量来检验结果类取决于分类变量的零假设。有关列联表和卡方检验的更多详细信息,请查看视频:https://www.youtube.com/watch?v=misMgRRV3jQ

    为了对连续数据进行分类,可以使用多种技术,从简单的基于频率的分箱到先进的方法,例如最小描述长度和基于熵的分箱方法。

    对连续变量使用卡方检验的优点是可以捕捉到与结果变量的非线性关系。

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 2013-08-15
      • 2016-03-16
      • 1970-01-01
      • 2022-07-27
      • 2015-11-21
      • 2014-11-05
      • 2014-02-05
      相关资源
      最近更新 更多