R试图使插入符号/rfe起作用
我有一个数据集,我正试图使用R on中的R试图使插入符号/rfe起作用,r,R,我有一个数据集,我正试图使用R on中的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
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
此外:
>y1-x1子集
>控制键
知道我为什么会收到这个消息吗?
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
vs
它应该是因子和向量:
as.factor(noquote(as.vector(t(df[,14]))))
在我的例子中,第14列是df中的一个类。就是这样做的。非常感谢你。
> 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
as.factor(noquote(as.vector(t(df[,14]))))