如何使用逻辑回归进行递归特征消除?

时间:2017-01-15 11:35:27

标签: r r-caret feature-selection

有人能为我提供一个使用插入符号rfe函数与glm或glmnet模型的详细示例吗?我试过这样的事情:

rfe_records <- Example_data_frame

rfe_ctrl <- rfeControl(functions = caretFuncs, method = "repeatedcv", repeats = 5, verbose = TRUE, classProbs = TRUE, summaryFunction = twoClassSummary)

number_predictors <- dim(rfe_records)[2]-1

x <- dplyr::select(rfe_records, -outcomeVariable)
y <- as.numeric(rfe_records$outcomeVariable)

glmProfile <- rfe(x, y, rfeControl = rfe_ctrl, sizes = c(1:number_predictors), method="glmnet", preProc = c("center", "scale"), metric = "Accuracy")
print(glmProfile)

但我得到的结果并不是我所需要的。我将Accuracy指定为度量标准,但我得到了:

Recursive feature selection

Outer resampling method: Cross-Validated (10 fold, repeated 5 times) 

Resampling performance over subset size:

 Variables   RMSE Rsquared  RMSESD RsquaredSD Selected
         1 0.5047  0.10830 0.04056    0.11869        *
         2 0.5058  0.09386 0.04728    0.11332         
         3 0.5117  0.08565 0.04999    0.10211         
         4 0.5139  0.07490 0.05042    0.10048         
         5 0.5166  0.07678 0.05456    0.09966         
         6 0.5202  0.08203 0.06174    0.10822         
         7 0.5187  0.08471 0.06207    0.10893         
         8 0.5168  0.07850 0.05939    0.09697         
         9 0.5175  0.08228 0.05966    0.10068         
        10 0.5176  0.08180 0.05980    0.10042         
        11 0.5179  0.08015 0.05950    0.09905         

The top 1 variables (out of 1):
   varName

1 个答案:

答案 0 :(得分:1)

根据this page caret使用结果变量的类,当它确定是否使用回归或分类时,可以使用glmnet这样的函数。根据您的代码,您使用as.numeric()将结果变量指定为数字,因此glmnet选择进行回归,而不是按照您的意图进行分类。将结果变量指定为两级因子,以获得分类。

相关问题