在随机森林中拆分训练和测试数据的查询

queries in spliting train and test data in Random Forest

我有一个包含 15 个变量和 4669 个观测值的数据框。

我正在使用随机森林进行建模。我的数据集的目标是预测特定产品是否会被客户接受。

所以,我的输出变量有因子 "Yes"、"No" 和“”。

我的问题是,我是否有可能在随机森林中将这个 "" 预测为是或否?

示例数据如下所示

Outputvar <- c("Yes", "Yes", "No", "NO", "", "")
Inputvar1 <- c("M", "F", "F", "M", "F", "M")
Inputvar2 <- c("34","25","40","50","60","34")
data <- data.frame(cbind(Outputvar,Inputvar2,Inputvar1))

我是 R 的新手,如果我的理解有误,那么谁能解释一下我可以做什么?

编辑:这是我迄今为止尝试过的代码

library(RandomForest)
data$outvar <- factor(data$outputvar, exclude = NULL)
ind0 <- sample(2, nrow(data), replace = TRUE, prob = c(0.7,0.3))
train0 <- data[ind0==1, ]
test0 <-  data[ind0==2, ]
fit1 <- randomForest(outputvar1~., data=train0)
print(fit1)
plot(fit1)

编辑2: 编号:3536 是:1061 "" : 72

My target from my data set is to predict is a particular product will be accepted by the customer or not.

so, my output variable has factors of "Yes", "No" and "".

嗯,没有。这里的实际上下文是:

您的输出变量只有两个因素,“是”和“否”;并且您的可用数据集有一部分您没有结果值 ("") 而您想预测它。

My question is, Is it possible for me to predict this "" , as Yes or No in random Forest ?

原则上,是的——这正是随机森林等分类器的用途。一般来说,您需要仅使用结果 (Yes/No) 确实可用的样本来训练您的模型(训练集,您可以将其中的一个子集用作测试集,以便评估您的模型表现);之后,您可以在其余数据集中使用 predict 来预测结果。

当然,这只是一个复合过程的4行总结,其中涉及到很多步骤,sub-steps这里无法详细分析,但希望能给你一个(非常)高层次的视图问题的(可以说,这就是您要问的)。我对 的回答也应该有用。