2014-09-08 3 views
4

데이터 세트를 가져 와서 교육 : 60 %, 테스트 : 20 % 및 유효성 검사 : 20 %의 세 부분으로 나누려고합니다. 내가 다시 분할 같은 일을 수행 할 때(캐럿 포함) : 테스트/교육/유효성 검사를위한 여러 크기의 파티션 만들기

part1 <- createDataPartition(fullDataSet$classe, p=0.8, list=FALSE) 
validation <- fullDataSet[-part1,] 
workingSet <- fullDataSet[part1,] 

는 :

Error in sort.list(y) : 'x' must be atomic for 'sort.list' 
Have you called 'sort' on a list? 

중 하나) 다른 크기의 3 개 파티션을 만들 수있는 방법이 있나요 :

inTrain <- createDataPartition(workingSet$classe, p=.75, list=FALSE) 

을 나는 오류 또는 b) 내가 시도한 것과 같은 중첩 된 파티션을 수행합니까? 나는 c) 대신에 sample()을 사용해 보았지만, 강사가 createDataPartition만을 사용하는 클래스를위한 것이고 코드를 보여줘야한다. 누구든지 여기에 조언이 있습니까?

답변

4

사실 나는 똑같은 것을 궁금해하고 있었고 매우 우아하지 않은 솔루션을 생각해 냈습니다.하지만 그건 효과가있는 것 같습니다.

필자의 경우, 데이터의 60 %와 테스트 및 유효성 검사 데이터 세트를 각각 20 %로하여 교육 데이터 세트를 만들고 싶었습니다. 여기 내가 그것을 한 적이 방법이다 : 그것은 나에게 올바른 데이터 세트를 제공하고 그들에게 오늘을 테스트 할 것 같은

set.seed(1234) 
inTraining <- createDataPartition(mydata$FLAG, p=0.6, list=FALSE) 
training.set <- mydata[inTraining,] 
Totalvalidation.set <- mydata[-inTraining,] 
# This will create another partition of the 40% of the data, so 20%-testing and 20%-validation 
inValidation <- createDataPartition(Totalvalidation.set$FLAG, p=0.5, list=FALSE) 
testing.set <- Totalvalidation.set[inValidation,] 
validation.set <- Totalvalidation.set[-inValidation,] 

것 같습니다. 희망이 있으면 도움이 될 것입니다. 다른 누군가가 좀 더 우아한 답변을 공유하면됩니다. :)

+0

이것은 내가하는 일입니다. 불행히도 더 많은'캐럿'네이티브 솔루션이나'createDataPartition'에 쓸 수있는 한 줄짜리 코드가 있는지 확신하지 못합니다. – NiuBiBang

0
#METHOD 1 : EQUAL SPLITS 
    # allind <- sample(1:nrow(m.d),nrow(m.d)) 
    # #split in three parts 
    # trainind <- allind[1:round(length(allind)/3)] 
    # valind <- allind[(round(length(allind)/3)+1):round(length(allind)*(2/3))] 
    # testind <- allind[round(length(allind)*(2/3)+1):length(allind)] 

    set.seed(1234) 

#METHOD 2 : 60-30-20 SPLIT 
allind <- sample(1:nrow(m.d),nrow(m.d)) 
trainind <- allind[1:round(length(allind)*0.6)] 
valind <- allind[(round(length(allind)*0.6)+1):((round(length(allind)*0.6)+1)+  
(round(length(allind)*0.3)))] 
testind <- allind[((round(length(allind)*0.6)+1)+ 
(round(length(allind)*0.3))+1):length(allind)] 
m.dTRAIN <- m.d[trainind,] 
m.dVAL <- m.d[valind,] 
m.dTEST <- m.d[testind,] 
+0

나는 그가 fullDataSet $ ​​classe에 의해 계층화되기를 원한다고 확신한다. – panterasBox