Welcome back.
We finally created some data that our boss can finally use the difference between wage and value of
a soccer player.
But this is kind of hard to read.
Wouldn't it be nice if we can visualize this data?
And that is a big thing that a data scientist does.
It analyzes the data, understands the data, cleans the data.
But at the end of the day, if you want to present this to anybody, you need it in a format that is
easily understandable for somebody that might not be a data science expert.
So let's visualize this.
Now, we talked about map plot lib, which is what is often used to visualize this data.
Now, this library is very extensive and you can read the documentation on your own, but a ton of other
libraries have been built on top of it to simplify and make it easier for us to visualize data.
One of these libraries is called Seabourn, and it's really, really easy to use.
Let me show you.
So we have this data.
If we go to a new cell block.
And just a reminder here, the way Jupyter Notebooks works is that it has to run all these inputs.
If you refresh Jupyter notebooks and you have a notebook and just click on Run for One Cell, it won't
have the previous cells in memory.
So you have to make sure that all these cells are run in order for you to execute this part.
Because if you just restarted Jupyter notebooks, it won't have any of this in memory.
But anyway, just wanted to make that note in case you have an error.
Let's use Seabourn to visualise the data we have above.
So again, Seaborne, you can just read the documentation and there's tons of tutorials online that
you can follow, but I'll just show you the easy way of doing it.
So we're going to import Seabourn, we're going to set up Seabourn by just running set.
And now we can just create a variable graph and call sense or sorry I should do c born as sense just
so we don't have to write Seabourn every time.
So sass dot set and then we're going to say graph equals sass and we're going to use the scatterplot
as the graphing method that we want to use.
And on the x axis we're going to use the wage and on the y axis we're going to use the value.
And the data we're going to use for the graph.
Is going to be data frame one, which is what we have up here.
So if I run this.
All right, we should have the graph now, so let's actually print it out.
If I click Run.
Look at that.
How easy was that?
Seaborne was important for me.
And all I had to do is say what graph I wanted, what were the values?
So that is the x axis and the y axis and what data we want to use.
And all of a sudden I have a graph.
How cool is that?
Just like that, using some really nice python libraries.
I now have a notebook that shows my progress of exploring this data.
But we have one problem here.
You see, I have all these scattered dots.
But I don't really know what they mean.
Wouldn't it be cool if there's a way for us to hover and actually see which player represents the dot?
Well, we can do that with another library, and this one is called Bouquet.
Bouquet.
It's a hard one to say.
Bulk bouquet, whatever you want to call it, is another library that allows us to actually have interactive
visualizations.
So again, if I go back, I can use it in a similar fashion that I did with Seabourn.
I simply say from.
BOQ.
BOQ is going to be really hard to say and I'm going to say dot plotting.
So from the plotting library, I'm going to import the figure and show functions.
And then also from the bouquet dot.
Models.
I'm going to import the hover tool, which is going to allow us to hover over these things.
Again, you don't have to memorize these.
If you go to the documentation and look at the Quickstart, you'll actually see this or you can even
Google for it.
So if we actually go to the Quick Start guide, you see that we have the two libraries that we import
it, plotting and models, and it shows you how to get started quickly.
As a matter of fact, we can just copy and paste this line, which allows us to plot title and X axis.
So let's do that.
And I'm going to give the title.
As Soccer 2019.
The x axis label will be wage and the y axis label will be value.
And here I can give a different parameters that perhaps I want.
For example, I can say plot width for how many pixels I want my plot with to be.
And same with plot.
Height.
We'll say we want that to be also 700 pixels.
And then finally I can say what type of tools I want to use.
In our case, we're going to create a hover tool so that we can hover over this.
Figure.
So this would be our graph right now.
Next.
If I do p dot show or actually the way it would work is we do the show that we import from here and
we run it like this.
And you know what?
For now, let's not use any of the hover tools.
If I click run here.
Well, looks like I have a bit of a mistake here.
I deleted Cho show by mistake.
Let's click run and look at that.
It actually opens up a new HTML file for me so that this could be interactive, but right now it's empty.
We actually have to draw the circles of our plot, but we have wage and value and the title Soccer 2019.
If we go to the Quickstart.
We see that we can do lines.
And we can do circles as well with different type of options.
And because we're doing a scatterplot.
Let's do exactly that.
I'll go back and.
And here.
Say that I want the circles that we're going to create.
And again, don't get too confused if this is new to you.
Again, this is all just a library and the documentation that you have to read if you want to get familiar
with it.
So we'll have the circle's wage and value.
So that is the x axis and the Y axis values all of the circles.
And then we'll say size.
We can give it a size of, let's say, ten for now.
And the source of the data will be from DF one.
So that's why we want the circles to contain.
If I now run this.
Well, I may have spelled something wrong.
This should be size.
If I click Run.
Look at that.
I have my data points, which is great, which is what we have before we have a new HTML file that's
generated.
But I want to be able to hover.
So if I go to let's close this for now.
If I go to the quick start guide and let's just search for hover, we see that we have the hover tool.
And we have all these options that we can use for hovering again.
Well, like this one.
But I'll just show you the basic syntax.
Essentially what we want to do is we use the hover.
To equal the hover tool that we're importing.
And in here we can say that the tool tips is going to equal a list that contains some tuples.
So it looks like we can use the tool tip like this.
So let me just copy this.
So we have the tooltips.
We have the index.
And then the X and y axis.
In our case, its wage and value.
And we'll change this to wage.
And value and we don't care about the ordering, but we actually want to add another field, which is
the name of the player.
From the data.
So as you can see.
In the Hover Tooltips section or for basic tooltips.
It'll show you exactly what each value represents and how you can represent it.
And you have the dollar signs and the add signs.
So in our case, we want to individually have the wage and the value displayed here.
So we're going to use the add sign, unlike the x and Y dollar sign, which just simply gives us the
x and y value.
So I'm just going to change this to the add sign and then finally also have the name property as well.
Now, the final thing we need to do is to just give this tool tips as the tools inside of this.
Figure parameter if I now run this.
Oop.
It looks like another error.
Let's see.
So it should be hover tool here.
And give it the array.
That we want.
So that if I run.
Hey, look at that.
We have an interactive plot that we can actually analyze.
So we see here that Neymar is well has a pretty low wage compared to his value.
What about Messi here?
Well, Messi is definitely getting paid a lot compared to his value.
So you might find some good deals for trades, maybe with Mbappe.
Very, very cool.
Now, this is just the tip of the iceberg when it comes to visualization libraries like this.
There's a lot of trial and error and learning how the library works, how to visualize this properly.
And up until now, all we've done is this part, right?
We've imported the data and then clean the data and maybe have done some visualizations with it.
We haven't really done any of these parts yet.
Up until now, what we've been doing is mostly data science, trying to grab data and understand it
for business purposes.
I want you to explore this data, set a little bit more, maybe try out some of these data visualization
libraries.
But for now, I think we have enough to move on and get into some more machine learning concepts.
I'll see you in the next one.
Bye bye.