全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4726 4
2015-11-25
悬赏 100 个论坛币 已解决
使用randomForest()函数处理数据后,直接调用plot()函数,得到图形如下,请问该图各条线如何解释,怎么添加图例?

最佳答案

neuroexplorer 查看完整内容

From what you showed, there is no test result (namely ytest was empty for training): Black solid line is for overall OOB (out-of-bag) error and, colour lines, one for each class' error (i.e. 1-this class recall). Suppose you use IRIS data, then:The red curve is the error rate for the Setosa class, the green and blue curves above are for Versicolor and Virginica while the black curve is the O ...
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-11-25 23:03:14
From what you showed, there is no test result (namely ytest was empty for training):

Black solid line is for overall OOB (out-of-bag) error and, colour lines, one for each class' error (i.e. 1-this class recall).

Suppose you use IRIS data, then:The red curve is the error rate for the Setosa class, the green and blue curves above are for Versicolor and Virginica while the black curve is the Out-of-Bag error rate.


The code is as following:

plot(fit)
legend(1500, 0.15, c('line 1', 'line 2', 'line 3', 'line 4'),
       lty=c(1,1,1,1),
       lwd=c(2.5,2.5, 2.5,2.5),
       col=c('black', "blue","red", 'green'))

附件列表
example.png

原图尺寸 25.22 KB

example.png

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-11-26 15:12:26
rfMt<-randomForest(x=xda[Idx,],y=yv[Idx],xtest=xda[-Idx,],ytest=yv[-Idx],ntree=1500)
用str() 显示模型结果 :
str(rfMt)
List of 17
$ call           : language randomForest(x = xda[Idx, ], y = yv[Idx], xtest = xda[-Idx, ], ytest = yv[-Idx], ntree = 1500,      corr.bias = TRUE)
$ type           : chr "regression"
$ predicted      : Named num [1:120] 1.22 2.06 1.58 1.91 1.45 ...
  ..- attr(*, "names")= chr [1:120] "69" "303" "22" "13" ...
$ mse            : num [1:1500] 0.394 0.349 0.322 0.311 0.316 ...
$ rsq            : num [1:1500]

................................
........................
$ y              : num [1:120] 1.79 2.08 1.39 1.61 1.1 ...
$ test           :List of 4
  ..$ predicted: Named num [1:83] 1.78 1.71 1.69 1.74 1.94 ...
  .. ..- attr(*, "names")= chr [1:83] "5" "9" "12" "14" ...
  ..$ mse      : num [1:1500] 0.392 0.292 0.303 0.316 0.305 ...
  ..$ rsq      : num [1:1500] 0.345 0.512 0.493 0.471 0.49 ...
  ..$ proximity: NULL
$ inbag

注:红色部分即为plot(rfMat)输出部分,但不完美,因此,可自已编程绘制:
  yda<-data.frame(oobmse=rfMt$mse,testmse=rfMt$test$mse)
> library(tidyr)
> yda$id<-1:1500
> str(yda)
'data.frame':   1500 obs. of  3 variables:
$ oobmse : num  0.394 0.349 0.322 0.311 0.316 ...
$ testmse: num  0.392 0.292 0.303 0.316 0.305 ...
$ id     : int  1 2 3 4 5 6 7 8 9 10 ...
> yda<-gather(yda,key=Type,value=mse,-id)
> str(yda)
'data.frame':   3000 obs. of  3 variables:
$ id  : int  1 2 3 4 5 6 7 8 9 10 ...
$ Type: Factor w/ 2 levels "oobmse","testmse": 1 1 1 1 1 1 1 1 1 1 ...
$ mse : num  0.394 0.349 0.322 0.311 0.316 ...
> library(ggplot2)
> ggplot(yda,aes(x=id,y=mse,colour=Type))+geom_line()
当然按自已的要求进一步美化!!!


当然mse 仅仅说明ntree 指标设置是否合理。test集的mse 则是一个预测性好坏的指标。
mse : (regression only) vector of mean square errors: sum of squared residuals divided  by n.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-3-10 09:11:34
请问楼主,随机森林的R语言包怎么安装到R语言上的,我是小白,不太懂
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-9-18 15:32:02
neuroexplorer 发表于 2015-11-25 23:03
From what you showed, there is no test result (namely ytest was empty for training):

Black solid  ...
你好,请问用建立随机森林模型的时候自己的数据集是否有格式要求,比如每行每列放什么东西?
谢谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群