Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Carson Sievert and Kenny Shirley have put together the really nice LDAvis R package. It provides a Shiny-based interactive interface for exploring the output from Latent Dirichlet Allocation topic models. If you've never used it, I highly recommend checking out their XKCD example (this paper also has some nice background).
LDAvis doesn't fit topic models, it just visualises the output. As such it is agnostic about what package you use to fit your LDA topic model. They have a useful example of how to use output from the lda package.
I wanted to use LDAvis with output from the topicmodels package. It works really nicely with texts preprocessed using the tm package. The trick is extracting the information LDAvis requires from the model and placing it into a specifically structured JSON formatted object.
To make the conversion from topicmodels output to LDAvis JSON input easier, I created a linking function called topicmodels_json_ldavis
. The full function is below. To use it follow these steps:
Create a
VCorpus
object using the tm package'sCorpus
function.Convert this to a document term matrix using
DocumentTermMatrix
, also from tm.Run your model using topicmodel's
LDA
function.Convert the output into JSON format using
topicmodels_json_ldavis
. The function requires the output from steps 1-3.Visualise with LDAvis'
serVis
.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.