我有一个数据集,我正在尝试使用R中的caret包中的rfe()。
X是我试图预测的价格。
Y是我用来做预测的变量。
我无法让rfe停止给出以下错误消息:
> lmProfile2 <- rfe(x1,y1,
+ sizes = subsets,
+ rfeControl = ctrl)
Error in rfe.default(x1, y1, sizes = subsets, rfeControl = ctrl) :
there should be the same number of samples in x and y以下是一些信息:
> class(x1)
[1] "data.frame"
> class(y1)
[1] "data.frame"
> nrow(x1)
[1] 500
> nrow(y1)
[1] 500
> ncol(x1)
[1] 68
> ncol(y1)
[1] 1另外:
> y1 <- data.frame(y = tiny4[,2])
> x1 <- data.frame(tiny4[,-c(1,2)])
> subsets <- c(5,10)
>
> ctrl <- rfeControl(functions = lmFuncs,
+ method = "cv",
+ verbose = FALSE,
+ returnResamp = "final")
> 你知道为什么我会收到这个消息吗?
发布于 2012-02-05 04:19:39
y应为数值或因子向量。在这里,您将其作为一个数据框。比较:
> rfe(data.frame(matrix(rnorm(100*3), ncol=3)), sample(2, 100, replace=T), sizes=1:3, rfeControl=rfeControl(functions=lmFuncs))
Recursive feature selection
Outer resampling method: Bootstrap (25 reps)
Resampling performance over subset size:
Variables RMSE Rsquared RMSESD RsquaredSD Selected
1 0.5154 0.02120 0.02421 0.02752 *
2 0.5162 0.02295 0.02722 0.03204
3 0.5162 0.02295 0.02722 0.03204
The top 1 variables (out of 1):
X3与
> rfe(data.frame(matrix(rnorm(100*3), ncol=3)), data.frame(sample(2, 100, replace=T)), sizes=1:3, rfeControl=rfeControl(functions=lmFuncs))
Error in rfe.default(data.frame(matrix(rnorm(100 * 3), ncol = 3)), data.frame(sample(2, :
there should be the same number of samples in x and y发布于 2018-12-01 12:28:17
它应该是因子和向量:
as.factor(noquote(as.vector(t(df[,14])))) 在我的例子中,列14是df中的一个类。
https://stackoverflow.com/questions/9143610
复制相似问题