如何使用 LOOCV 在 R 中找到比完整集分类更好的子集

How to use LOOCV to find a subset that classifies better than full set in R

我正在使用 faraway 包中的 wbca 数据。恶性肿瘤采样的先验概率为π0 = 1/3,良性肿瘤采样的先验概率为π1 = 2/3。

我正在尝试将朴素贝叶斯分类器与多项式一起使用,看看是否有 9 个特征的一个很好的子集比使用 LOOCV 的完整集分类得更好。

我什至不确定从哪里开始,所以任何 Rcode 帮助都会很棒。谢谢!

您可以尝试以下操作,预测变量的核估计可能不是最准确的,但您可以从以下开始:

library(faraway)
library(naivebayes)
library(caret)

x = wbca[,!grepl("Class",colnames(wbca))]
y = factor(wbca$Class)

ctrl <- rfeControl(functions = nbFuncs,
                   method = "LOOCV")

bayesProfile <- rfe(x, y,
                 sizes = subsets,
                 rfeControl = ctrl)

bayesProfile

Recursive feature selection

Outer resampling method: Leave-One-Out Cross-Validation 

Resampling performance over subset size:

 Variables Accuracy  Kappa Selected
         2   0.9501 0.8891         
         3   0.9648 0.9225         
         4   0.9648 0.9223         
         5   0.9677 0.9290         
         6   0.9750 0.9454        *
         7   0.9692 0.9322         
         8   0.9750 0.9455         
         9   0.9662 0.9255         

The top 5 variables (out of 6):
   USize, UShap, BNucl, Chrom, Epith

可以获得最优变量:

bayesProfile$optVariables
[1] "USize" "UShap" "BNucl" "Chrom" "Epith" "Thick"