scikitlearn中递归特征消除(RFE)的排序与得分

2024-09-28 21:39:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图理解如何读取RFECV中的grid_scores_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])

我该怎么读ranking_grid_scores_越低的排名值是否越好?(或者维切弗萨?)。之所以这么问,是因为我注意到,排名最高的功能通常在grid_scores_中得分最高。

然而,如果某物有一个ranking = 1不应该意味着它被列为组中最好的吗?。这也是文档says

"Selected (i.e., estimated best) features are assigned rank 1"

但现在让我们看看下面的示例,使用一些实际数据:

> rfecv.grid_scores_[np.nonzero(rfecv.ranking_ == 1)[0]]
0.0

而排序值最高的特征得分最高。

> rfecv.grid_scores_[np.argmax(rfecv.ranking_ )]
0.997

注意,在上面的示例中,排名=1的特性得分最低

文档中的图:

关于这个问题,在文档中的this figure中,y轴读取"number of misclassifications",但它正在绘制使用'accuracy'grid_scores_(?)作为评分函数。标签不应该读y吗?(越高越好)而不是"number of misclassifications"越低越好)


Tags: from文档importfalsetrue示例makesklearn
1条回答
网友
1楼 · 发布于 2024-09-28 21:39:42

您是正确的,因为排名较低的值表示一个好的特性,并且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.

因此grid_scores_值与特定特征不对应,它们是特征的子集的交叉验证错误度量。在这个例子中,具有5个特征的子集是信息量最大的集合,因为grid_scores_中的第5个值(包含5个最高级特征的SVR模型的CV值)是最大的。

您还应该注意,由于没有显式指定评分标准,因此使用的评分器是SVR的默认值,即R^2,而不是准确性(这仅对分类器有意义)。

相关问题 更多 >