的findThoughts函數返回錯誤「提供文本和建模文件數數不匹配」時長(文本)!= out.stm的行數。
這是來自用於處理文檔的textProcessor函數的錯誤在調用'stm'函數之前。
這就是爲什麼會發生這種情況: 臨時輸出有一個屬性temp $ docs.removed,它列出了已刪除的行。所以「臨時文件$」的長度會比溫度$ docs.removed的長度「意見」較小。
所以STM對象「a」和它使用的臨時文件$將具有相同長度的臨時文件$建模的$ THETA(與文件專題概率矩陣)。
temp<-textProcessor(comments, metadata=NULL, lowercase=TRUE, removestopwords=TRUE, removenumbers=TRUE, removepunctuation=TRUE, stem=TRUE, wordLengths=c(3,Inf), sparselevel=1, language="en", verbose=TRUE, onlycharacter= FALSE, striphtml=FALSE, customstopwords=NULL, onlytxtfiles=TRUE)
meta<-temp$meta
vocab<-temp$vocab
docs<-temp$documents
a<-stm(documents=docs, vocab=vocab, K=7,data=meta, max.em.its=800)
解決方案:刪除在「臨時」的對象被拆除從「文本」的對象,這些文件。下面的代碼通過創建一個新的向量z來刪除temp $ docs.removed中引用的索引。
z<-comments[-temp$docs.removed,]
length(z)
thoughts3 <- findThoughts(a,texts=z,topics=3, n=10,thresh=0.0)