I try to implement in R test for appropriate metrics for lda.

Here the way I try to use LDA

dtext <- data.frame(id = c(1,2,3), text = c("This dataset contains movie reviews along with their associated binary sentiment polarity labels. It is intended to serve as a benchmark for sentiment classification. This document outlines how the dataset was gathered, and how to use the files provided.", "The core dataset contains 50,000 reviews split evenly into 25k train and 25k test sets. The overall distribution of labels is balanced (25k pos and 25k neg). We also include an additional 50,000 unlabeled documents for unsupervised learning.", "There are two top-level directories [train/, test/] corresponding to the training and test sets. Each contains [pos/, neg/] directories for the reviews with binary labels positive and negative. Within these directories, reviews are stored in text files named following the convention [[id]_[rating].txt] where [id] is a unique id and [rating] is the star rating for that review on a 1-10 scale. For example, the file [test/pos/200_8.txt] is the text for a positive-labeled test set example with unique id 200 and star rating 8/10 from IMDb. The [train/unsup/] directory has 0 for all ratings because the ratings are omitted for this portion of the dataset."),stringsAsFactors = F)

    corp_news <- corpus(dtext)

    dfmat_news <- dfm(corp_news, remove_punct = TRUE, remove = stopwords('en')) %>% 
        dfm_remove(c('*-time', '*-timeUpdated', 'GMT', 'BST')) %>% 
        dfm_trim(min_termfreq = 0.95, termfreq_type = "quantile", 
                 max_docfreq = 0.1, docfreq_type = "prop")

    dfmat_news <- dfmat_news[ntoken(dfmat_news) > 0,]
    dtm <- convert(dfmat_news, to = "topicmodels")
    lda <- LDA(dtm, k = 10)

Which are the parameters which I have to test to make the perfomance of lda better? example there methods for the topic selection number algorithms like gibbs, recover and recoverl2 what other tunning it needs?


The main and by far most impactful parameter that you have to search for is k - the number of topics you assume. Conceptually, this is similar to K Nearest Neighbors, in which you have to pre-specify the number of clusters you are searching for and then determine the best fit clusters by properties of the clustering results.

The other parameters, including the method of solving the mathematical problem may produce slightly different results, but none will be nearly as impactful as k.

On a more general note, you can almost always find the answer to this question for an implemented algorithm you're trying to use from the API documentation of the package in question- the topicmodels documentation containing the LDA interface can be found here.

Often, if you don't well understand the properties of the algorithm that you're trying to use, the documentation will also point you to resources which thoroughly describe the algorithm in question. It is this understanding of the algorithm and what it is doing that will enable you to answer the questions like "What parameters should I tune, over what values, and what is likely to change about the outputs when I do so?"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.