from sklearn.datasets import load_iris from sklearn.feature_selection import SelectKBest from sklearn.feature_selection import chi2
时间: 2023-11-19 14:05:10 浏览: 122
机器学习笔记2–sklearn之iris数据集
# Load the Iris dataset
iris = load_iris()
# Separate the features and target variable
X = iris.data
y = iris.target
# Apply SelectKBest to select the 2 best features using chi-squared test
selector = SelectKBest(chi2, k=2)
X_new = selector.fit_transform(X, y)
# Print the selected features
print("Selected Features: ", selector.get_support(indices=True))
阅读全文