fit_lda: Perform topic modeling on preprocessed reviews

View source: R/topic_modeling.R

fit_ldaR Documentation

Perform topic modeling on preprocessed reviews

Description

This function performs LDA topic modeling on the preprocessed reviews.

Usage

fit_lda(dtm, k, method = "Gibbs")

Arguments

dtm

A document-term matrix

k

The number of topics to extract

method

The method to use for fitting the model (default: Gibbs)

Value

An LDA model

Examples


# 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)


Goodreader documentation built on Oct. 30, 2024, 9:11 a.m.