2013-04-29 4 views
4

R (~ 1000 단어 인 ~ 6400 문서의 코퍼스에 100 개의 항목)에 topicmodels 패키지를 사용하려고합니다. 프로세스가 실행되고 종료되면 메모리가 부족해지기 때문에 생각합니다.topicmodels를 사용하기 위해 DocumentTermMatrix에서 단어를 제거하려고 시도했습니다

그래서 나는 lda() 함수가 입력으로 취하는 문서 용어 행렬의 크기를 줄이려고합니다. 내 문서 용어 행렬을 생성 할 때 minDocFreq 함수를 사용하여 할 수 있다고 생각합니다. 그러나 내가 그것을 사용할 때 어떤 차이도없는 것처럼 보인다. 여기

코드 비트 관련된다 :

> corpus <- Corpus(DirSource('./chunks/'),fileEncoding='utf-8') 
> dtm <- DocumentTermMatrix(corpus) 
> dim(dtm) 
[1] 6423 4163 
# So, I assume this next command will make my document term matrix smaller, i.e. 
# fewer columns. I've chosen a larger number, 100, to illustrate the point. 
> smaller <- DocumentTermMatrix(corpus, control=list(minDocFreq=100)) 
> dim(smaller) 
[1] 6423 41613 

동일한 크기 및 동일한 열 개수 (용어 즉, 동일한 번호) 여기서 일부 코드이다.

내가 뭘 잘못하고 있는거야? 감사.

답변

12

귀하의 질문에 대한 답은 여기에 있습니다 : https://stackoverflow.com/a/13370840/1036500가 (그에게 upvote에 줘!)

tm 패키지에 대한 간단한, 최신 버전에서

예를 들어, bounds를 사용하는 대신 minDocFreq을 포함하지 않지만, 당신의

smaller <- DocumentTermMatrix(corpus, control=list(minDocFreq=100)) 

지금해야

require(tm) 
data("crude") 

smaller <- DocumentTermMatrix(crude, control=list(bounds = list(global = c(5,Inf)))) 
dim(smaller) # after Terms that appear in <5 documents are discarded 
[1] 20 67 
smaller <- DocumentTermMatrix(crude, control=list(bounds = list(global = c(10,Inf)))) 
dim(smaller) # after Terms that appear in <10 documents are discarded 
[1] 20 17