我正在看这个教程:https ://www.dataquest.io/mission/75/improving-your-submission
在第 8 节,寻找最佳特征,它显示了以下代码。
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
predictors = ["Pclass", "Sex", "Age", "SibSp", "Parch", "Fare", "Embarked", "FamilySize", "Title", "FamilyId"]
# Perform feature selection
selector = SelectKBest(f_classif, k=5)
selector.fit(titanic[predictors], titanic["Survived"])
# Get the raw p-values for each feature, and transform from p-values into scores
scores = -np.log10(selector.pvalues_)
# Plot the scores. See how "Pclass", "Sex", "Title", and "Fare" are the best?
plt.bar(range(len(predictors)), scores)
plt.xticks(range(len(predictors)), predictors, rotation='vertical')
plt.show()
k=5 是做什么的,因为它从未被使用过(图表仍然列出了所有功能,无论我使用 k=1 还是 k="all")?它如何确定最佳特征,它们是否独立于人们想要使用的方法(无论是逻辑回归、随机森林还是其他)?