View source: R/topic_modeling.R
fit_lda | R Documentation |
This function performs LDA topic modeling on the preprocessed reviews.
fit_lda(dtm, k, method = "Gibbs")
dtm |
A document-term matrix |
k |
The number of topics to extract |
method |
The method to use for fitting the model (default: Gibbs) |
An LDA model
# Create a temporary file with sample book IDs
temp_file <- tempfile(fileext = ".txt")
writeLines(c("1420", "2767052", "10210"), temp_file)
# Scrape reviews
reviews <- scrape_reviews(temp_file, num_reviews = 5, use_parallel = FALSE)
# Preprocess the reviews
preprocessed <- preprocess_reviews(reviews, english_only = TRUE)
# Fit LDA model
lda_model <- fit_lda(preprocessed$dtm, k = 2)
# Print model summary
print(lda_model)
# Clean up: remove the temporary file
file.remove(temp_file)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.