Ich möchte alle Dokumente in 10 Themen zu teilen, und es geht gut mit einem konvergierten Ergebnis mit Ausnahme der Dimensionen der Verteilungen und Kovarianz Matrix des Themas.
Warum ist die Themenverteilung ein Vektor mit 9 Dimensionen statt 10 und ihre Kovarianzmatrix ist 9 * 9 Matrix statt 10 * 10?Verschiedene Dimensionen von Verteilungen von Themen
Ich habe library(topicmodels)
und Funktion CTM()
, um das Topic-Modell in Chinesisch zu implementieren.
mein Code unten:
library(rJava);
library(Rwordseg);
library(NLP);
library(tm);
library(tmcn)
library(tm)
library(Rwordseg)
library(topicmodels)
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Law.scel","Law");
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\NationalInstitution.scel","NationalInstitution");
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Place.scel","Place");
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Psychology.scel","Psychology");
installDict("C:\\Users\\Jeffy\\OneDrive\\Workplace\\R\\Politics.scel","Politics");
listDict();
#read file
d.vec <- segmentCN("samgovWithoutID.csv", returnType = "tm")
samgov.segment <- read.table("samgovWithoutID.segment.csv", header = TRUE, fill = TRUE, stringsAsFactors = F, sep = ",",fileEncoding='utf-8')
fix(samgov.segment)
# create DTM(document term matrix)
d.corpus <- Corpus(VectorSource(samgov.segment$content))
inspect(d.corpus[1:10])
d.corpus <- tm_map(d.corpus, removeWords, stopwordsCN())
ctrl <- list(removePunctuation = TRUE, removeNumbers= TRUE, wordLengths = c(1, Inf), stopwords = stopwordsCN(), wordLengths = c(2, Inf))
d.dtm <- DocumentTermMatrix(d.corpus, control = ctrl)
inspect(d.dtm[1:10, 110:112])
# impletment topic models
ctm10<-CTM(d.dtm,k=10, control=list(seed=2014012692))
Terms10 <- terms(ctm10, 10)
Terms10[,1:10]
ctm20<-CTM(d.dtm,k=20, control=list(seed=2014012692))
Terms20 <- terms(ctm20, 20)
Terms20[,1:20]
Das Ergebnis in R Studio (siehe Markierung Teil):
Hilfedokument:
Bitte geben Sie ein [reproduzierbares Beispiel] an (http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – figurine
Danke für Ihren Kommentar! – Jeffy