楼主: benbobo
15971 25

[问答] 求助----关于R语言的randomforest包的一个问题 [推广有奖]

  • 0关注
  • 0粉丝

小学生

0%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
23 点
帖子
2
精华
0
在线时间
5 小时
注册时间
2012-5-2
最后登录
2012-10-10

楼主
benbobo 发表于 2012-5-2 19:55:35 |AI写论文
10论坛币
在R语言的randomForest程序包中,randomForest函数中的第一个参数是formula,文章中的解释是a formula describing the model to be fitted.
有两个例子,一个这么写的:iris.rf<-randomForest(Species~.,iris)
另一个是ozone.rf<-randomForest(Ozone~.,data=airquality)
就是说这两个例子的formula一个是Species~.,另一个是Ozone~.,
这两个例子中的Species~.,和Ozone~.,分别是什么含义?
对于我自己要跑的数据,这个formula应该怎么定义?

谢谢各位大虾了~~~

关键词:randomForest Forest random rand Rest 文章 程序

回帖推荐

epoh 发表于2楼  查看完整内容

iris data: three species : setosa, virginica and versicolor (3分类) Four features : the length and the width of the sepals and petals(4特性) #### library(randomForest) data(iris) iris Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 ...

本帖被以下文库推荐

沙发
epoh 发表于 2012-5-2 21:37:37
iris data:
  three species : setosa,  virginica and  versicolor (3分类)
  Four features : the length and the width of the sepals and petals(4特性)
####
library(randomForest)
data(iris)
iris
    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1            5.1         3.5          1.4         0.2     setosa
2            4.9         3.0          1.4         0.2     setosa
3            4.7         3.2          1.3         0.2     setosa
.....
.....
148          6.5         3.0          5.2         2.0  virginica
149          6.2         3.4          5.4         2.3  virginica
150          5.9         3.0          5.1         1.8  virginica


set.seed(71)
randomForest(Species ~ ., data=iris, importance=TRUE)
等同
set.seed(71)
randomForest(Species ~Sepal.Length + Sepal.Width + Petal.Length + Petal.Width , data=iris, importance=TRUE)

Call:
randomForest(formula = Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width, data = iris, importance = TRUE)
               Type of random forest: classification
                     Number of trees: 500
No. of variables tried at each split: 2

        OOB estimate of  error rate: 4%
Confusion matrix:
           setosa versicolor virginica class.error
setosa         50          0         0        0.00
versicolor      0         47         3        0.06
virginica       0          3        47        0.06

再有问题,把数据传上来

藤椅
benbobo 发表于 2012-5-2 21:50:28
好的,谢谢了,这个明白了。
那set.seed(71),这句话是什么意思?括号中的数字是什么含义?

板凳
epoh 发表于 2012-5-2 22:15:22
benbobo 发表于 2012-5-2 21:50
好的,谢谢了,这个明白了。
那set.seed(71),这句话是什么意思?括号中的数字是什么含义?
set.seed()
主要是让每次结果相同
否则你我的电脑执行出来的结果不同
你可能会产生质疑

>?set.seed

报纸
ttatacter 发表于 2012-5-17 16:55:02
Species~.,和Ozone~.,都是表示应变量,也就是response variable。
set.seed表示设置种子数,设置不同的种子数时会随机得到不同的抽样结果。为了使运行的结果可重复,比如:别人运行你的程序的时候,也能得到跟你一模一样的结果,这时就需要设置种子数,相当于固定了抽到的样本,就能计算得到固定的结果。

地板
294117186 发表于 2012-7-3 20:40:09
请问,有没有办法把分类错误的项提出来

7
ttatacter 发表于 2012-12-2 22:45:50
294117186 发表于 2012-7-3 20:40
请问,有没有办法把分类错误的项提出来
似乎不能,因为随机森林考虑的本来就是一个整体,是看这个森林的总体效能,而非对某一个case的效能。就算能,我觉得提出来的意义也不大。个人意见,仅供参考。

8
yuandfang 发表于 2012-12-5 18:23:58
这两个例子中的Species~.,和Ozone~.,分别是那个数据集的列名字,就是用这一列和其他的列做一个randomforest。
R软件中间很多的案例写法都是一样的,Species~.,和Ozone~.这种写法的程序在SVM和决策树模型中都有。你不妨看看,有助于你对Species~.,和Ozone~.的理解。

9
晓茜 发表于 2013-6-30 16:07:42
epoh 发表于 2012-5-2 21:37
iris data:
  three species : setosa,  virginica and  versicolor (3分类)
  Four features : the leng ...
你好,我想问一下RF用的是什么交叉验证方法呢?是jackknife还是k-fold?计算结果中有一行No. of variables tried at each split: 2,这是什么意思?是指的是2-fold交叉验证么?

10
luolxy 发表于 2013-7-1 09:02:41
天5一就好 j

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-20 03:05