【发布时间】:2015-08-07 03:07:39
【问题描述】:
当我尝试来自here 的“caret”包中的 rfe 示例时,我不断收到此错误
Error in rfe.default(d[1:2901, ], c(1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, :
there should be the same number of samples in x and y
这个问题has been asked 但它的解决方案不适用于这种情况。
代码如下:
set.seed(7)
# load the library
library(mlbench)
library(caret)
# load the data
d <- read.table("d.dat")
# define the control using a random forest selection function
control <- rfeControl(functions=rfFuncs, method="cv", number=10)
# run the RFE algorithm
results <- rfe(d[1:2901, ], c(1,1,1,1, 1, 1,2,2,2, 3 ,3,3,4, 4, 4), sizes=c(1:2901), rfeControl=control)
# summarize the results
print(results)
数据集是一个包含 2901 行(特征)和 15 列的数据框。向量 c(1,1,1,1,1,1,2,2,2,3,3,3,4,4,4) 是特征的预测变量。
我设置错了什么参数?
【问题讨论】:
-
为我工作!!!,请检查这个答案。 stackoverflow.com/questions/48902732/…