In the next couple of lessons I want to show you two things. 1
First I want to show you how to install third party modules and packages that don't come bundled with 2
the Anaconda distribution that we're running. 3
But more importantly, I want to show you a data visualization technique for giving prominence to words 4
that appear more frequently in a piece of text, namely the word cloud. A word cloud or a tag cloud as 5
it is also called looks like this. 6
The idea behind a word cloud is that the words that are larger appear more frequently than those that 7
are smaller. Here, 8
I've used the Wikipedia article on machine learning to generate this particular word cloud. 9
Notice how the larger tags catch your attention. 10
You'll probably find that you're not actually reading all the words in this visualization at all. 11
Instead people just tend to scan these word clouds. 12
So, why use this technique? 13
It's not scientific and it's not accurate. 14
True, but more often than not, you need to grab people's attention and a word cloud can do this rather 15
well. 16
It's a little bit of a novel visualization. 17
It's a bit creative and it communicates the relative importance of the words in the dataset very quickly. 18
After all it's pretty easy to see that a word that's twice the size of another word is probably twice 19
as important. 20
And in our case it appears twice as often. 21
Speaking of grabbing people's attention, you can get even more creative with the word cloud by applying 22
a mask to the image. Here, 23
I've used a circle as a mask, but you could use another image instead. 24
For example, would you like to venture a guess as to what data I've used to create this word cloud in 25
the shape of a whale? 26
I actually used Herman Melville's novel, Moby Dick, and here I've used the data from our spam emails, and 27
here I've used Shakespeare's play Hamlet. 28
Coming up, I'll be showing you how to create all of these three visualizations. 29
That way you can apply this technique to your future projects. 30
I've seen a lot of people use word clouds on reports and presentations that say contain customer feedback 31
or metadata like tags or SEO keywords that will help you rank on Google or really any situation where 32
you quickly need to show how people feel about your product or your business. 33
These are the kind of applications where word clouds really shine. 34
All right. 35
So how do we create a word cloud in Python? Because we're not gonna do it from scratch. 36
We will use an existing Python package. 37
Now the fantastic thing about the Anaconda distribution is that it comes bundled with lots and lots 38
of different packages 39
straight out of the box. These included numpy, pandas, 40
matplotlib and many others that we've already used. 41
However, the Python ecosystem is actually huge and you'll often find that you'll want to make use of 42
a package that's not installed by default. 43
In that case, you'll need to know how to download and install a custom package to add to your collection. 44
For that, you'll be using the terminal if you're running a Mac or the Anaconda prompt on Windows. 45
Both of these kind of look like this and this is where you can execute many different types of commands. 46
The command that we'll be looking at in detail is called "conda install" 47
and the easiest way to install a package is just to type "conda install" followed by the package name. 48
However, this won't always work and it actually won't work in the case of our word cloud package. 49
And the reason is is that we also have to specify something called a channel. A channel is the location 50
where conda will look for the package. 51
If you just write "conda install" and then the package name, then conda will search in a default location 52
which may or may not contain the package that you're looking for. 53
If you need to specify a particular channel or you know that the package exists, then all you have to 54
do is follow "conda install" with "-c" and then the channel name. This syntax, the "-c" works just 55
like you're supplying an argument to a Python function. 56
In our case, the wordcloud package is located in a channel called "conda-forge" and therefore the code 57
that we will be typing into our prompt will read "conda install -c conda-forge wordcloud". 58
Let me quickly show you how to do this on Mac and then I'll show you what you'll see on a Windows machine. 59
To see the existing packages that are already installed 60
fire up your Anaconda navigator and then click on Environments. There you can search for the existing 61
packages that are already installed on your computer. 62
The package that we're looking for is called "wordcloud", all in one word. 63
Now since I can't find it, I'm going to open my terminal. There 64
I'm going to type "conda install wordcloud", but just as we've discussed earlier for the wordcloud package 65
we actually need to specify a channel, we need to specify a location because it's not found in the default 66
location where Conda is looking. 67
Instead we need to type "conda install -c conda-forge wordcloud" and if you don't make 68
any typos, then you should see your computer starting to do some work. Prior to going ahead with the installation 69
you may have to confirm that you actually want to do this and then you have to type "y" for yes to proceed. 70
At this point a download will start 71
and once the download is finished, you'll see something like "Preparing transaction", "Verifying transaction", 72
"Executing transaction". 73
*Drum roll* 74
And then you're good to go. Once you see these messages 75
I encourage you to fire up Finder, go to the Anaconda folder, then go to the packages folder and then 76
find the wordcloud subfolder there. 77
This is the package that you've just installed. Back in the Anaconda Navigator, 78
you can now type in "wordcloud" into the search bar and it should pop up. 79
Mind you, I actually had to restart my Anaconda Navigator for it to pick this up. And that pretty much 80
concludes the setup for Mac. On Windows, 81
the story is pretty much the same. If you fire up the Anaconda Navigator and search for "wordcloud" it 82
doesn't appear. To bring up the Anaconda prompt, 83
all you need to do is click on that little place symbol and then say "Open Terminal". 84
This will fire up the Anaconda prompt where you can type in "conda install -c conda-forge 85
wordcloud". 86
Now depending on the speed of your machine, this might take a little while, but you can't go away and grab 87
a coffee just yet, because once again you need to type in "y" to confirm and proceed. After you've done 88
that a download will start 89
and I'm actually fast forwarding my video here because this took a little bit longer on this machine, 90
but at the end you'll see the very same messages that we saw on Mac - "Preparing transaction", "Verifying 91
transaction", "Executing transaction". 92
*Drum roll* 93
And that's it. 94
If you'd like to see where these packages were actually installed on your computer, go to your user directory, 95
so mine's called "P.D" 96
under Users, but yours will have your own name of course. 97
Then open Anaconda 98
3, then go to the packages folder and there, 99
if you scroll further down you should see the wordcloud package along with the others that start with 100
"w". Back in the Anaconda Navigator, 101
you won't necessarily find the wordcloud package listed already, 102
you might have to actually quit and restart this thing, because only then does it seem to pick it up. 103
Now you're pretty much all set to install any package you come across in the future. 104
All you need to do after all is type "conda install", then the channel where the package is located and 105
then the package name and that's it. In the next lesson, 106
it's time to write some Python code and actually create these word clouds. 107
So I hope you're looking forward to that as much as I am. 108
I'll see you there.