Welcome back.
In this video, we'll start our journey
into the spider chart.
And let me do shift enter.
And what I want to have a look first is the data frame dot date.
So look at the data so that we kind of start to visualize what we need with a
spider chart.
And here let me do data frame dot head
and control enter.
So we have these six predictors and we
need to create this spider chart with these six variables.
At the same time, we know that we need to normalize the data because for instance,
life expectancy is 71 and generosity is 0 .something.
So there's this big discrepancy between
the values.
And this is what we are going to start.
So we need to import functions.
So from sklearn import preprocessing.
And here we go.
And then we normalize with the min max scalar.
This is the better option for this type of charts.
And that is because we kind of have this, you know, between 0 and 1.
So that everything has the same exact scale.
So min max scalar equals 2.
And then we import the class.
So preprocessing dot min max scalar.
And then parenthesis.
So this is important.
And I am going to kind of create a new data frame.
So data frame underscore scaled equals our data frame.
And then I go to our data frame underscore scaled.
But I'm just going to focus on everything that starts from 2 on.
We can also include happiness, right?
So this is an option.
Or better yet, let's include it as well, so that we kind of have everything.
And then if we want to remove it, then we can as well.
So square brackets.
I want all of the rows starting from
index position 1 relating to happiness.
And then over here equals.
And then we use the min max scalar to fit and transform parenthesis.
And what we do here is that we transform the data frame underscore scaled.
Or better yet, data frame dot ilog is also an option.
So here starting from 1 onward.
So we are creating a data frame
underscore scaled.
And then we are basically transforming
the variables inside the data frame and replacing them in the new data frame
underscore scaled.
Let's have a look at the outputs.
So data frame underscore scaled dot head.
And then here we go.
So everything will be kind of between 0 and 1.
Or better yet, everything will be exactly between 0 and 1.
And the next thing is that we need to prepare these categories.
There's two things here.
So how many are there?
And because we have this spider radial chart, we need to calculate the angles.
Let's start with categories.
So if we list our data frame, so list
data frame underscore scaled.
And so this will be something.
So these are the variable.
So these are the variables.
And if we just want starting from the index position 1, we just have happiness
and so on.
So these are the categories.
So equals to this.
And then we need to know how many.
So n equals to the length of categories.
And here you go.
So let me do shift enter.
The next thing is to compute the angles.
And this is where each of the categories will be.
So we divide 360, right?
So 360 by the number of variables.
And how does this actually work?
Or how does this actually look like?
So our angles n equals 2.
So angles and then it is n divided by the
float of n.
And then times 2 times and one thing I
forgot to import .
So from math import pi.
So this is important.
And then so times and not one but rather two times pi for n in range n.
And here you go.
And then let's look at our angles.
So control enter.
We have the 00 and then we have 0 .89, 1
.79 and so on.
Now, of course, this does not make a lot
of sense yet.
And we need to do this second
transformation, which is when we go to angles.
And then we do so up until the last one.
So and if you look at the angles now, here you go.
So this is the most important thing so that we go from 0 and we end in 0.
Also, just to clarify, right?
So this will not kind of be the typical angles.
After the categories, we need to compute the position of the categories.
So here we go.
And we will call this angles.
It's not angles per se, but we'll call it like that.
And what we do is that we are basically dividing n divided by the float.
So float of n times two times pi for n in range n.
So let's have a look.
So angles.
Control enter.
And here you go.
So from 0, then 0 .89, 1 .8 and so on.
And all of this would be or would be the
way to go.
The next thing that we would do is that
we should end with 0 at the end.
So what we do is that we do angles and
then plus equal and then angles and then up until the last one.
Then let's see the outcome.
So angles.
And here you go.
So we end at 0.
The last thing that I want to prepare is to pick countries.
And I'll just take it in a very simple way.
So A equals to where I live, which is Germany.
And then B where I was from, which is Portugal.
Here we go.
Then shift enter.
I am going to stop here.
So we have kind of prepared everything.
And in the next video, we're going to
build our basic spider chart.
Until then, have fun.