R rfe 函数“插入符号"包错误:x 和 y 中的样本数应该相同 [英] R rfe function "caret" Package error: there should be the same number of samples in x and y
本文介绍了R rfe 函数“插入符号"包错误:x 和 y 中的样本数应该相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我正在尝试取自 这里,我一直收到这个错误
As I'm trying the rfe example from the "caret" package taken from here, I kept on receiving this error
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
这个问题已被问到但它的解决方案没有不适用于这种情况.
This question has been asked but its solution doesn't apply in this case.
代码如下:
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) 是特征的预测变量.
The dataset is a data frame of 2901 rows (features) and 15 columns. The vector c(1,1,1,1,1,1,2,2,2,3,3,3,4,4,4) is the predictor for the features.
我设置错了什么参数?
推荐答案
rfe(x, y,sizes = subsets, rfeControl = ctrl)
你的问题是你没有 x 行的 nr 与向量 y 的长度相同
Your problem is that you dont have the nr of rows of x as same length of the vector y
这篇关于R rfe 函数“插入符号"包错误:x 和 y 中的样本数应该相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文