随机森林模型中具有递归特征消除功能的特征选择错误

问题描述 投票:1回答:1

我有数百个样本,并且已经将它们分为四个不同的类别(集群)。现在,我有兴趣确定将样本分类为不同类别的最佳基因集。

我想应用具有递归特征消除功能的randomforest并检测基因(特征)。我的数据如下所示。只是在此处发布一些示例数据。

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9IUjg3QkJjLnBuZyJ9” alt =“在此处输入图像描述”>

上面的数据只是一个例子:我的原始数据在数据框df中,第一列有100个样本,第二列和第3到1002列有4类,总共有1000个具有表达值的基因。

我正在使用下面的代码,但我看到有错误。

library(caret)
library(mlbench)
library(Hmisc)
library(randomForest)

# define the control using a random forest selection function
control <- rfeControl(functions=rfFuncs, method="cv", number=10)

# run the RFE algorithm
results <- rfe(df[,3:1002], df[,2], sizes = df[,1:1002], rfeControl=control)

出现错误:我觉得我在某处做错了。

Error in summary.connection(connection) : invalid connection

这里是上述数据的dput

df <-structure(list(Samples = structure(c(1L, 8L, 9L, 10L, 11L, 12L, 
13L, 14L, 15L, 2L, 3L, 4L, 5L, 6L, 7L), .Label = c("Sample1", 
"Sample10", "Sample11", "Sample12", "Sample13", "Sample14", "Sample15", 
"Sample2", "Sample3", "Sample4", "Sample5", "Sample6", "Sample7", 
"Sample8", "Sample9"), class = "factor"), Class = structure(c(1L, 
2L, 3L, 1L, 2L, 4L, 2L, 1L, 1L, 4L, 1L, 3L, 4L, 1L, 1L), .Label = c("Class1", 
"Class2", "Class3", "Class4"), class = "factor"), Gene1 = c(1.030078784, 
0.944152632, 0.140700452, 0.013432323, 0.265233165, -0.084496727, 
4.835469554, 0.089434913, -0.433436179, 1.462895475, -0.116005356, 
1.007868422, 0.244881864, -1.495666899, 0.364368654), Gene2 = c(1.407236415, 
1.229003431, -0.322221459, -1.361955252, 0.310963955, 0.80115063, 
4.27765356, 0.872413223, -0.568249851, 1.187873069, -0.255284575, 
1.878058722, -0.767371822, -0.859697473, 0.057304769), Gene3 = c(0.200772234, 
-0.048349737, 1.224274924, 0.492396142, 0.500786902, -0.731802706, 
1.853246564, 1.611995455, 0.287088678, 0.509235514, 2.031735375, 
3.074950771, 2.069407179, 0.886158642, 1.736798303), Gene4 = c(1.23309207, 
1.321282889, 2.403301108, 0.748860637, 1.019200751, 1.393254607, 
2.667976275, 1.158136576, 1.89503732, 2.178257717, 0.747697632, 
2.834410716, 0.028594536, -0.411039831, 1.100167946), Gene5 = c(0.883005616, 
0.570786704, 0.72649548, 4.705893892, 0.086345885, 0.502530136, 
2.681497202, 0.640362079, 0.327319762, 2.086767741, 1.853085301, 
1.001799748, 0.126208601, 0.911621722, 0.671191951), Gene6 = c(2.590519025, 
3.076688902, 1.77414005, 1.014363629, 1.134652225, 2.71957962, 
4.696379063, -0.301828123, 1.214261665, 2.413881644, -0.470794827, 
0.520494891, 0.194511306, 0.075331863, 2.315680177), Gene7 = c(0.088929673, 
0.472549468, -0.125630236, -0.069648505, -0.715250242, 0.068554966, 
4.131662998, -0.075265565, -1.234425917, 0.343350342, 0.190414782, 
1.153495806, 0.210317581, -0.475603641, 0.294299351), Gene8 = c(2.112231178, 
2.780100532, 2.423828553, 1.569215682, 1.018119196, 2.583413401, 
6.483053565, 2.215201821, 1.893325529, 2.342058862, 4.001423142, 
4.221704757, 1.978211867, 1.452633851, 2.556589741)), class = "data.frame", row.names = c(NA, 
-15L))

任何人都可以告诉我如何使用上述数据并应用随机森林来了解哪些基因将样本分为不同的类别。比>]

我有数百个样本,并且已经将它们分为四个不同的类别(集群)。现在,我有兴趣确定将样本分类为不同...的最佳基因集。]]

r random-forest r-caret feature-selection rfe
1个回答
1
投票

大小是指您想尝试并保留的功能数量,应为数字,但您在df[,1:1002]中提供了一些奇怪的内容。

请参见下面的内容,在这里我模拟一个数据集并正确设置大小以确保其运行以选择最佳数量的要素(根据您提供的内容):

© www.soinside.com 2019 - 2024. All rights reserved.