运行randomForest时出错:找不到对象 [英] Error in running randomForest : object not found

查看:372
本文介绍了运行randomForest时出错:找不到对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试为我的数据集拟合一个随机森林分类器.我对R非常陌生,我想这是一个简单的格式化问题.

So i am trying to fit a random forest classifier for my dataset. I am very new to R and i imagine this is a simple formatting issue.

我读取了一个文本文件并转换了我的数据集,使其具有以下格式:(取出机密信息)

I read in a text file and transform my dataset so it is of this format: (taking out confidential info)

>head(df.train,2)

   GOLGA8A     ITPR3   GPR174  SNORA63    GIMAP8     LEF1    PDE4B LOC100507043    TGFB1I1    SPINT1
Sample1  3.726046 3.4013711 3.794364 4.265287 -1.514573 7.725775 2.162616    -1.514573 -1.5145732 -1.514573
Sample2 4.262779 0.9261892 4.744096 7.276971 -1.514573 4.694769 4.707387     2.031476 -0.8325444  2.615991
...
...
CD8B     FECH    PYCR1 MGC12916     KCNA3 resp
Sample1  -1.514573 2.099336 3.427928 1.542951 -1.514573    1
Sample2 -1.145806 1.204241 2.846832 1.523808  1.616791    1

从本质上讲,列是我的特征,行是我的样本,最后一列是我的响应向量,是一列因子,分别.

In essence the columns are my features and the rows my samples, the last column is my response vector which is a column of factors, resp.

然后我用:

set.seed(1) #Set the seed in order to gain reproducibility

RF1 = randomForest(resp~., data=df.train,ntree=1000,importance=T,mtry=3)

只需尝试使用其他列作为功能来训练我的列resp上的RF.

Simply trying to train the RF on my column resp using the other columns as features.

但是我得到了错误:

Error in eval(expr, envir, enclos) : object 'PCNA-AS1' not found

但是,查看我的训练集,我可以清楚地找到该列,例如:

However, looking into my training set I can clearly find that column, e.g with:

sort(unique(colnames(df.train))

所以我真的不明白错误或从这里去哪里.如果没有以正确的方式提出问题,我深表歉意,感谢您的所有帮助!

So I don't really understand the error or where to go from here. My apologies if I haven't posed the question in the correct way, thanks for any and all help!

推荐答案

总之, 这是一个非常新手的错误,我输入的是矩阵而不是导致错误的data.frame.为什么它抱怨那个特定的列(不是第一列)与另一个我仍然不明白的列相比. 感谢您的所有帮助. 干杯, 安东尼

So in short, It was a very rookie mistake, i was inputting a matrix rather than a data.frame which was causing this error. Why it was complaining about that particular column (which was not the first) compared to another i still don't understand. Thanks for all the help. Cheers, Anthony

这篇关于运行randomForest时出错:找不到对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆