相关疑难解决方法(0)

Sklearn Chi2用于功能选择

我学习卡方特征选择和整个代码就喜欢这个

但是,我对chi2的理解是,分数越高,表示该功能独立(因此对模型的使用较少),因此我们对分数最低的功能感兴趣。但是,使用scikit可以学习SelectKBest,选择器将返回具有最高 chi2分数的值。我对使用chi2测试的理解不正确吗?还是sklearn中的chi2分数产生了chi2统计量以外的结果?

请参阅下面的代码以了解我的意思(除结尾外,大部分都是从以上链接复制而来)

from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
import pandas as pd
import numpy as np

# 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)
chi2_selector.fit(X, y)

# Look at scores returned …
Run Code Online (Sandbox Code Playgroud)

python machine-learning chi-squared feature-selection scikit-learn

5
推荐指数
1
解决办法
2133
查看次数