【问题标题】:output the predicted value of random forest as a new column in the test dataset将随机森林的预测值输出为测试数据集中的新列
【发布时间】:2015-12-22 21:20:49
【问题描述】:

我在训练数据集(父数据集的 60%)上运行随机森林。

我使用 R 中的“预测”函数来评估模型在测试数据集(父数据集的 40%)上的表现如何

我用过

 require(randomForest)

 trained_model <- randomForest(y~.,data = training,
                                   importance=TRUE, 
                                   keep.forest=TRUE)

 result <- predict(trained_model, type = response, newdata=testing[-17])

删除第 17 列,因为它是“y”

问题是“结果”是一个数组,这有一种方法可以将此预测值作为新列添加回测试数据集中

有点像

Id     x1     x2 ......   Xn    y     predicted
1      0.1    0.12        23    no    no 

【问题讨论】:

标签: r random-forest


【解决方案1】:

这样做:

testing[ ,(ncol(testing)+1)] <- result

将结果添加回测试数据集时,会有一列而不是数组。

【讨论】:

    猜你喜欢
    • 2021-03-21
    • 2014-04-15
    • 2020-10-20
    • 2014-08-07
    • 2019-07-22
    • 2016-09-02
    • 2019-05-04
    • 2019-07-21
    相关资源
    最近更新 更多