Text Analytics Part II – Term Document Matrix and WordCloud using R

My last post was on web crawling and extraction of reviews and ratings from flipkart for MOTO G (2nd generation) phone. Hope you have files and R-code saved on your system. If not you can go through the post again, here is the link.

Creation of Term-Document matrix:

A document-term matrix or term-document matrix is a mathematical matrix that describes the frequency of terms that occur in a collection of documents. In a document-term matrix, rows correspond to documents in the collection and columns correspond to terms. There are various schemes for determining the value that each entry in the matrix should take. One such scheme is tf-idf.

What is TF-IDF?

tf–idf, short for term frequency–inverse document frequency, is a numerical statistic that is intended to reflect how important a word is to a document in a collection or corpus of words.
I have created two TDM matrices: one with frequency of terms in each documents and other with tf-idf scores of each terms within each document.

Word Cloud Formation:

It is an image composed of words used in a particular text or subject, in which the size of each word indicates its frequency or importance.
I have created WordCloud on the basis of frequency of each terms used in each document and it comes out to be:

Word Cloud

Words like “phone”, “battery”, “moto”, “good”, “camera” etc. got highlighted in this cloud. So we can say that people have used these words too much in their statements. They have talked about camera, battery, screen, display, means hardware specifications a lot. They have also talked about its “performance”, “price”, “time”, “better” etc. which means they have expressed their views on the performance of this phone. Word “flipkart” got highlighted, as this phone is only available on flipkart hence they might have talked about the delivery process of flipkart. Rest words that are displayed in smallest font size, are also important words but their frequency count is little less. From these words we can say that people have compared this phone with similar Xiaomi and Samsung products.

R Code to do this:

#creating wordcloud
#packages required:- tm,wordcloud

This is a chunk of code for doing this specific task, I will soon share the full code in my subsequent post.

In my next post, I will continue working on reviews, will do dimension reduction using LSA, keep following Text Analytics Part III

Share the joy

Leave a Reply

Notify of