View source: R/topic_modeling_core.R
predict.lda_topic_model | R Documentation |
Obtains predictions of topics for new documents from a fitted LDA model
## S3 method for class 'lda_topic_model'
predict(
object,
newdata,
method = c("gibbs", "dot"),
iterations = NULL,
burnin = -1,
...
)
object |
a fitted object of class |
newdata |
a DTM or TCM of class |
method |
one of either "gibbs" or "dot". If "gibbs" Gibbs sampling is used
and |
iterations |
If |
burnin |
If |
... |
Other arguments to be passed to |
a "theta" matrix with one row per document and one column per topic
## Not run:
# load some data
data(nih_sample_dtm)
# fit a model
set.seed(12345)
m <- FitLdaModel(dtm = nih_sample_dtm[1:20,], k = 5,
iterations = 200, burnin = 175)
str(m)
# predict on held-out documents using gibbs sampling "fold in"
p1 <- predict(m, nih_sample_dtm[21:100,], method = "gibbs",
iterations = 200, burnin = 175)
# predict on held-out documents using the dot product method
p2 <- predict(m, nih_sample_dtm[21:100,], method = "dot")
# compare the methods
barplot(rbind(p1[1,],p2[1,]), beside = TRUE, col = c("red", "blue"))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.