나는 수백 개의 샘플을 가지고 있으며 이미 그것들을 4 개의 다른 클래스 (클러스터)로 분류했습니다. 이제 저는 샘플을 다른 클래스로 분류하는 최상의 유전자 세트를 식별하는 데 관심이 있습니다.
재귀 적 기능 제거 기능이있는 randomforest를 적용하고 유전자 (특징)를 감지하고 싶습니다. 내 데이터는 다음과 같습니다. 여기에 예제 데이터를 게시하십시오.
위의 데이터는 예일뿐입니다. 내 원래 데이터는 df
첫 번째 열에 100 개의 샘플이 있고 두 번째 열에 4 개의 클래스가 있고 열 3에서 열 1002까지 총 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))
누구든지 위의 데이터를 사용하고 임의의 숲을 적용하여 샘플을 다른 클래스로 분류하는 유전자를 알 수있는 방법을 알려주세요. thanq.
크기는 시도하고 유지하려는 기능의 수를 나타내며 숫자 여야하지만에서 이상한 것을 제공했습니다 df[,1:1002]
.
아래와 같이 데이터 세트를 시뮬레이션하고 크기를 올바르게 설정하면 최적의 기능 수 (제공 한 것)를 선택할 수 있습니다.
library(caret)
library(mlbench)
library(Hmisc)
library(randomForest)
set.seed(101)
df = data.frame(samples=paste0("Samples",1:99),
Class=paste0("Class",rep(1:3,33)),
matrix(rnorm(99*1000),ncol=1000))
colnames(df)[3:ncol(df)]=paste0("Gene",1:1000)
# we create like 100 informative genes for Class1 and Class2
df[df$Class=="Class1",3:103] = df[df$Class=="Class1",3:103] + rpois(33*100,1.5)
df[df$Class=="Class2",104:203] = df[df$Class=="Class2",104:203] + rpois(33*100,1.5)
control <- rfeControl(functions=rfFuncs, method="cv", number=2)
# run the RFE algorithm
results <- rfe(df[,3:1002], df[,2], sizes = c(50,100,200),
rfeControl=control)
위에서 50,100 또는 200 개의 유익한 기능을 요청하면 다음을 얻습니다.
results
Recursive feature selection
Outer resampling method: Cross-Validated (2 fold)
Resampling performance over subset size:
Variables Accuracy Kappa AccuracySD KappaSD Selected
50 0.9792 0.9688 0.02946 0.04419
100 0.9896 0.9844 0.01473 0.02210
200 1.0000 1.0000 0.00000 0.00000 *
1000 1.0000 1.0000 0.00000 0.00000
The top 5 variables (out of 200):
Gene94, Gene198, Gene137, Gene136, Gene158
> results$optsize
[1] 200
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다