How to create a wordcloud and what is it helpful for Explain with an example?

How to create a wordcloud and what is it helpful for Explain with an example?

How to create a wordcloud and what is it helpful for Explain with an example?

This recipe helps you create a wordcloud and what is it helpful for Explain with an example


Recipe Objective

How to create a wordcloud and what is it helpful for?

Wordcloud is nothing but a data visualization technique mainly used for text representation it is also called a tag cloud. In this, the size of each word indicates its frequency or importance of that word. It displays a list of words, the importance of each is shown by font color or size.

What is it useful for: Analyzing text data from social media websites. Significant textual points can be highlighted using a word cloud. In a Customer service process useful to analyze customer feedback. Identifying new SEO(Search engine optimization) Keyword to target. And Many More...

Step 1 - Install Wordcloud

!pip install wordcloud

Step 2 - Import the necessary libraries

from wordcloud import WordCloud, STOPWORDS import matplotlib.pyplot as plt import pandas as pd

Step 3 - Take a sample data set

df_sample = pd.read_csv('/content/Youtube_Comments_data.csv', encoding ="latin-1") df_sample.head()

For sample data we are using youtube comments data on videos of famous artist.

Step 4 - Store comments in a simple string and stopwords in a variable

words_comments = '' My_stopwords = set(STOPWORDS)

Step 5 - Iterate through the Sample data.

for elements in df_sample.CONTENT: elements = str(elements) tokenization = elements.split() for i in range(len(tokenization)): tokenization[i] = tokenization[i].lower() words_comments = words_comments + " ".join(tokenization)+" "

Here in the above in first for loop we are firstly typecasting the each element into string then splitting the values. After that in the second for loop we are converting each value into lower case.

Step 5 - Create wordcloud for visualization

My_wordcloud = WordCloud(width = 800, height = 800, background_color ='white', stopwords = My_stopwords, min_font_size = 10).generate(words_comments)

Step 6 - Plot the cloud Image

plt.figure(figsize = (8, 8), facecolor = None) plt.imshow(My_wordcloud) plt.axis("off") plt.tight_layout(pad = 0)

Relevant Projects

Resume parsing with Machine learning - NLP with Python OCR and Spacy
In this machine learning resume parser example we use the popular Spacy NLP python library for OCR and text classification.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Census Income Data Set Project - Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based on census data.

Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

PySpark Tutorial - Learn to use Apache Spark with Python
PySpark Project-Get a handle on using Python with Spark through this hands-on data processing spark python tutorial.

Build a Collaborative Filtering Recommender System in Python
Use the Amazon Reviews/Ratings dataset of 2 Million records to build a recommender system using memory-based collaborative filtering in Python.