Welcome back.
We learned about distribution of MPG histogram.
Now let's create a heatmap visualization to show relationships between numerical features in data set.
Create a new code set.
Start with plt dot figure.
Figure size ten by eight and set the heatmap using SNS.
This is the newly created and imported library that we used before, which is the seaborn as SNS.
And as I told you, Seaborn data visualization library built on top of Matplot library.
It provides a high level interface for creating attractive statistical graphics.
So we're going to use this library to create our heat map SNS dot heatmap.
Creating the heatmap.
Passing the parameters.
Data set dot.
Correct the annotation true.
See map.
Cool.
Worm.
Worm and line width is 0.5.
The title.
Give it the coloration heatmap and the plot dot show.
I'm using the Matplot library.
Also we can name it as feature coloration, heatmap or matrix.
Okay, let's run and see.
And here we go.
This is our heatmap.
It's very very amazing I love this type of heatmaps.
And here we go.
Let me explain what we've done here and what this heatmap means.
Back to our code.
Here we have the coloration dataset dot coloration.
The coloration calculates the the numerical values between the features.
Coloration values range between -1 to 1, so please write those notes down.
Dataset dot correlation calculates the correlation matrix between all numerical columns minus one to
plus one.
The correlation values ranges from -1 to 1 one.
Perfect positive correlation zero.
No correlation minus one.
Perfect negative correlation.
Now we have the heat map.
And this is the main heat map creation.
As I told you we passed the correlation matrix.
The annotation through displays the actual correlation values on the heatmap.
Cool warm colors were blue represents negative coloration.
So the negative coloration would be in blue.
So blue color represents the negative coloration.
The red color represents the positive color correlation.
Okay and zero centers the color map to zero, which is neutral, and the title is uh feature coloration
correlation heatmap.
And let's display the final result like this.
So we're going to interpret it.
Diagonals always show 1.0 with each variable perfectly correlated with itself.
So MPG is correlated with mpg origin is present and correlated with origin symmetric mirrored across
the diagonals.
So we have asymmetry.
Color intensity indicates coloration strength.
As I told you, blue is, uh, the high blue and the more intense blue is perfectly negative coloration
and positively coloration is in red.
So NPG is strongly correlated with NPG with itself.
Numbers show exact coloration correlation coefficients.
Okay, so this coloration heatmap shows relationships between automotive features from what appears
to be a vehicle data set.
So here we have we have eight columns and cylinders placement horsepower weight acceleration model year
and origin.
So this is a very important way to display the feature coloration using this heatmap.
Strong positive correlation red high value.
So here we have this square this red square.
So for example cylinders and displacement.
So this is the cylinders.
And this is displacement 0.95 very strong cylinders.
And weight is 0.93 cylinders.
Uh sorry cylinders.
And weight is 0.90.93.
Displacement and weight.
They are very very strong.
Displacement and horsepower is 0.9.
Also very strong here.
As an interpretation, we conclude that vehicles with more cylinders tend to have larger engines displacement
more, horsepower and weight more.
Also, we have strong negative correlation blue high negative values.
Here we have this blue box.
And here we have a blue box the mpg and weight, so mpg and the weight is zero -0.83.
Strongest and negative mpg and displacement -0.81 mpg and cylinder 0.75 78 and mpg and horsepower -0.78.
Fuel efficiency mpg decreases as vehicles get heavier, have larger engines, more cylinders, and more
horsepower.
So this is the coloration that this heatmap tries to gives us.
And to, to uh, allow us to conclude this conclusion.
So positive relationships between MPG and model year is 0.58.
You notice that this mpg and model year 58 mpg and origin is 0.57.
Newer vehicles and certain origins tend to have better fuel efficiency, but this is not a very big
deal.
So I want from you to understand the colors and the coefficients.
Vehicles with more horsepower tend to have slower acceleration, likely because they are heavier.
If we get the horsepower and the acceleration.
So here the acceleration and the horsepower -0.69.
Vehicles with more horsepower tend to have slower acceleration.
Those are the negative correlation.
Okay.
So this heat map reveals the classic automotive engineering trade off between performance and fuel economy.