Description Usage Arguments Value Examples
View source: R/topic_modeling_core.R
Obtains predictions of topics for new documents from a fitted LSA model
1 2 |
object |
a fitted object of class "lsa_topic_model" |
newdata |
a DTM or TCM of class dgCMatrix or a numeric vector |
... |
further arguments passed to or from other methods. |
a "theta" matrix with one row per document and one column per topic
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # Load a pre-formatted dtm
data(nih_sample_dtm)
# Convert raw word counts to TF-IDF frequency weights
idf <- log(nrow(nih_sample_dtm) / Matrix::colSums(nih_sample_dtm > 0))
dtm_tfidf <- Matrix::t(nih_sample_dtm) * idf
dtm_tfidf <- Matrix::t(dtm_tfidf)
# Fit an LSA model on the first 50 documents
model <- FitLsaModel(dtm = dtm_tfidf[1:50,], k = 5)
# Get predictions on the next 50 documents
pred <- predict(model, dtm_tfidf[51:100,])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.