Ame*_*ina 6 python machine-learning scikit-learn
我试图了解如何阅读grid_scores_
和RFECV中的ranking_
值.以下是文档中的主要示例:
from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = SVR(kernel="linear")
selector = RFECV(estimator, step=1, cv=5)
selector = selector.fit(X, y)
selector.support_
array([ True, True, True, True, True,
False, False, False, False, False], dtype=bool)
selector.ranking_
array([1, 1, 1, 1, 1, 6, 4, 3, 2, 5])
Run Code Online (Sandbox Code Playgroud)
我怎么看ranking_
和grid_scores_
?是较低的排名值越好?(或相反亦然?).问这个的原因是因为我注意到排名最高的功能通常是最高分grid_scores_
.
但是,如果有什么ranking = 1
不应该意味着它被评为最佳组合?.这也是文档说的:
" 选定(即估计最佳)特征被指定为等级1 "
但是现在让我们看一下使用一些真实数据的以下示例:
> rfecv.grid_scores_[np.nonzero(rfecv.ranking_ == 1)[0]]
0.0
Run Code Online (Sandbox Code Playgroud)
而与该功能最高排名值具有最高的*分数*.
> rfecv.grid_scores_[np.argmax(rfecv.ranking_ )]
0.997
Run Code Online (Sandbox Code Playgroud)
请注意,在上面的示例中,排名为1的要素得分最低
在这个问题上,在文档中的这个图中,y
轴读取"number of misclassifications"
,但它是grid_scores_
使用'accuracy'
(?)作为评分函数的绘图.y
标签不应该读accuracy
?(越高越好)而不是"number of misclassifications"
(越低越好)
你是正确的,因为低排名值表示一个好的特征,并且grid_scores_
属性中的高交叉验证分数也很好,但是你误解了这些值的grid_scores_
含义.来自RFECV文档
grid_scores_
array of shape [n_subsets_of_features]
The cross-validation scores such that grid_scores_[i] corresponds to the CV score of the i-th subset of features.
Run Code Online (Sandbox Code Playgroud)
因此,grid_scores_
值不对应于特定特征,它们是特征子集的交叉验证误差度量.在该示例中,具有5个特征的子集证明是最具信息性的集合,因为第5个值grid_scores_
(包含5个最高排名特征的SVR模型的CV值)是最大的.
您还应注意,由于未明确指定评分指标,因此使用的记分器是SVR的默认值,即R ^ 2,而不是准确度(这仅对分类器有意义).
归档时间: |
|
查看次数: |
5905 次 |
最近记录: |