predict.lsa_topic_model: Predict method for LSA topic models

Description Usage Arguments Value Examples

View source: R/topic_modeling_core.R

Description

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

Usage

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

Arguments

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.

Value

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

Examples

 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,])

Example output

Loading required package: Matrix

Attaching package: 'textmineR'

The following object is masked from 'package:Matrix':

    update

The following object is masked from 'package:stats':

    update

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