2012-02-09 9 views
1

EDIT : 작업 영역의 개체가 충돌하여 예기치 않은 동작이 발생하는 문제입니다.tm DocumentTermMatrix에 짧은 토큰 포함

다음 코드를 사용하여 문서에서 DocumentTermMatrix를 만들려고합니다. 이 문서에는 많은 1 및 2 문자 토큰이 들어 있습니다. 그러나, 최소 단어 길이가 1 문자로 설정된 경우에도, 결과 행렬은 699 개의 문서와 0 개의 용어를 포함합니다.

library(tm) 
data <- read.csv("http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",header=FALSE) 
data <- data[-1] 

training_data <- as.vector(apply(as.matrix(data, mode="character"),1,paste,collapse=" ")) 
corpus <- Corpus(VectorSource(training_data)) 

matrix <- DocumentTermMatrix(corpus,control=list(wordLengths=c(1,Inf))) 

데이터에 1과 2 개의 문자 토큰이 많음에도 불구하고 토큰이 생성되지 않는 이유는 무엇입니까?

" 4 8 8 5 4 5 10 4 1 4" 

답변

4

나는 당신이 윈도우 7 시스템에서 R 및 TM의 최신 버전에 준하고 (아래 참조) 찾고 있던 결과를 생산 정확히 실행 : 여기에 하나 개의 샘플 데이터 항목입니다. 작업 공간을 지우고 R을 종료하거나 재부팅을 시도합니다.

> library(tm) 
> data <- read.csv("http://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",header=FALSE) 
> data <- data[-1] 
> 
> training_data <- as.vector(apply(as.matrix(data, mode="character"),1,paste,collapse=" ")) 
> corpus <- Corpus(VectorSource(training_data)) 
> 
> matrix <- DocumentTermMatrix(corpus,control=list(wordLengths=c(1,Inf))) 
> matrix 
A document-term matrix (699 documents, 11 terms) 

Non-/sparse entries: 2899/4790 
Sparsity   : 62% 
Maximal term length: 2 
Weighting   : term frequency (tf) 
+0

때로는 문제를 찾기 위해 다른 컴퓨터에서 테스트해야 할 때도 있습니다. 도와 주셔서 감사합니다! –