【问题标题】:variable selection in r using knn使用knn在r中选择变量
【发布时间】:2013-06-19 03:00:02
【问题描述】:

我有一个包含 72 个观察值和 592 个变量的数据框 (df),其中包含一个因子类变量(总共 593 个变量,即 dim(df) = 72 593)。我正在寻找一种方法来选择 7 个变量(包括类变量),使用接收器操作特性 (ROC) 来选择最佳 k 值。我想通过图形模型使用这七个变量进行分析,但我不想随机选择变量。我希望我的选择在统计上是合理的。

我希望看到的结果类似于:

根据 ROC 的最高值选择变量 V23、V120、V230、V333、V496、V585、V593。

即我想对高精度的“最佳”预测变量进行分类和选择,以便我可以将这些变量用于图形建模。

我曾尝试使用 caret 包,但我不知道如何操作它来选择可用于其他分析的高精度变量(列)。

谢谢各位。相信有人理解我。

谢谢。

kutex。

【问题讨论】:

    标签: r knn roc


    【解决方案1】:

    我会这样做:

    library(pROC)
    
    #' Select the N top variables with ROC analysis
    #' @param response the class variable name
    #' @param predictors the variables names from which to select
    #' @param data must contain the predictors as columns
    #' @param n the number of 
    select.top.N.ROC <- function(response, predictors, data, n) {
        n <- min(n, length(predictors))
        aucs <- sapply(predictors, function(predictor) {
            auc(data[[response]], data[[predictor]])
        })
        return(predictors[order(aucs, decreasing=TRUE)][1:n])
    }
    
    top.variables <- select.top.N.ROC("class", paste("V", 1:593, sep=""), myDataFrame, 7)
    cat(paste("Variables", paste(top.variables, collapse=", "), "were selected based on the highest value of ROC. "))
    

    与任何单变量特征选择方法一样,您可以选择 7 个完全相关的变量,这些变量不会为您提供任何额外信息,因此选择 V23 就足够了。对于多元数据集,您应该考虑改用多元特征选择方法。

    【讨论】:

      猜你喜欢
      • 2019-06-24
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2021-05-21
      • 2015-06-06
      • 1970-01-01
      相关资源
      最近更新 更多