我是randomForest模型的新手,需要帮助。
我从我的火车data.frame创建了一个500棵树的随机森林,并为特定变量创建了一组响应预测。我需要将预测与表格中的原始观察结果进行比较。我该怎么做呢?我试着制作table(test, predictions)
但是有点难以理解桌子甚至告诉我的内容。
答案 0 :(得分:5)
由于您还没有提供数据,我试图复制它,这是我遵循的程序:
复制数据:
Level <- c("strongly disagree", "disagree", "no answer", "agree", "strongly agree")
Question5 <- c("strongly agree", "agree", "no answer", "disagree", "strongly disagree", "disagree", "no answer", "agree", "strongly disagree")
Question5 <- factor(Question5, levels=Level, ordered=T)
train <- data.frame(a=c(2,3,5,1,2,1,4,1,4), b=c(4,1,3,2,5,3,4,1,2), Question5)
Question5 <- c("strongly disagree", "no answer", "agree", "strongly disagree", "disagree", "strongly agree", "no answer", "disagree", "strongly agree")
Question5 <- factor(Question5, levels=Level, ordered=T)
test <- data.frame(a=c(4,3,5,2,1,3,4,2,5), b=c(5,2,3,1,4,3,2,4,1), Question5)
应用randomForest:
> library(randomForest)
> rf1 <- randomForest(Question5~., data=train, ntree=500)
> p1 <- predict(rf1, test, type='response')
> table(p1, test$Question5)
p1 strongly disagree disagree no answer agree strongly agree
strongly disagree 0 0 2 0 1
disagree 0 1 0 0 0
no answer 1 0 0 1 0
agree 1 0 0 0 1
strongly agree 0 1 0 0 0
当您对数据执行此过程时,您应该得到类似于我上面的表格。当您将此表的对角线元素相加时,您将获得正确预测的总数(在上述情况下,9个中的1个)。
答案 1 :(得分:0)
我用来评估模型的是:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class CustomNetworkManager : NetworkManager {
public override void OnClientDisconnect(NetworkConnection conn)
{
Debug.Log("TimeOutError");
}
}