Latent Dirichlet Allocation (LDA) to classify documents and text into topics
In this recipe, we will explore the Latent Dirichlet Allocation (LDA) algorithm in Spark 2.0. The LDA we use in this recipe is completely different from linear discrimination analysis. Both Latent Dirichlet Allocation and linear discrimination analysis are referred to as LDA, but they are extremely different techniques. In this recipe, when we use the LDA, we refer to Latent Dirichlet Allocation. The chapter on text analytics is also relevant to understanding the LDA.
LDA is often used in natural language processing which tries to classify a large body of the document (for example, emails from the Enron fraud case) into a discrete number of topics or themes so it can be understood. LDA is also a good candidate for selecting articles based on one's interest (for example, as you turn a page and spend time on a specific topic) in a given magazine article or page.
How to do it...
Start a new project in IntelliJ or in an...