predict.ctm_topic_model: Predict method for Correlated topic models (CTM)

Description Usage Arguments Value Note Examples

View source: R/topic_modeling_core.R

Description

Obtains predictions of topics for new documents from a fitted CTM model

Usage

1
2
## S3 method for class 'ctm_topic_model'
predict(object, newdata, ...)

Arguments

object

a fitted object of class "ctm_topic_model"

newdata

a DTM or TCM of class dgCMatrix or a numeric vector

...

further arguments passed to or from other methods.

Value

a "theta" matrix with one row per document and one column per topic

Note

Predictions for this method are performed using the "dot" method as described in the textmineR vignette "c_topic_modeling".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Load a pre-formatted dtm 
## Not run: 
data(nih_sample_dtm) 

model <- FitCtmModel(dtm = nih_sample_dtm[1:20,], k = 3,
                     calc_coherence = FALSE, calc_r2 = FALSE)

# Get predictions on the next 50 documents
pred <- predict(model, nih_sample_dtm[21:100,])

## End(Not run)

Example output

Loading required package: Matrix

Attaching package:textmineRThe following object is masked frompackage:Matrix:

    update

The following object is masked frompackage:stats:

    update

textmineR documentation built on June 28, 2021, 9:08 a.m.