WEBVTT

00:01.370 --> 00:07.310
In this video we learn how to create matrix plots and in particular heat maps to visualize cross tabular

00:07.310 --> 00:07.820
data.

00:08.150 --> 00:10.870
So we're going to see in a minute what I mean with this.

00:10.880 --> 00:15.550
And first of all we import pandas and seaborne met plot live.

00:16.040 --> 00:22.760
And again we are working with the Titanic data set and we've already learned that we can split our data

00:22.790 --> 00:26.930
into different groups and we can do this by categories.

00:26.930 --> 00:32.570
So for example we have the sixth column and the peak last column and in total we can create six different

00:32.570 --> 00:38.730
groups and then we can determine the size of each group so we can determine how many a first class mail

00:38.750 --> 00:41.930
passengers we had on board of the Titanic.

00:42.110 --> 00:47.570
And we can do this for example with the direct Panda's method the cross tab.

00:47.600 --> 00:51.510
So here we are passing the two categories to sex and peak class.

00:51.530 --> 00:54.880
And by doing so we are getting across tabular data.

00:54.890 --> 00:59.160
So here on the left hand side to the after category is female and male.

00:59.600 --> 01:01.630
And as columns we have two categories.

01:01.690 --> 01:07.220
First second and third class and for each combination of those two categories we FBA.

01:07.250 --> 01:11.630
Actually the amount of passengers that belong to this group.

01:11.900 --> 01:18.020
So for example the largest group by far is in the group made passengers in the third class.

01:18.020 --> 01:24.380
And this is pretty much the section that we need for a matrix plot heat map plot so we can actually

01:24.380 --> 01:31.460
visualize and compare the size of the six groups with a heat map and first flight we determine the figure

01:31.460 --> 01:32.800
size of twelve eight.

01:32.820 --> 01:40.970
And also we want to have a lot of fun scale here and then we are using the as an escort heat map and

01:40.970 --> 01:44.720
to pass our crust tab that we created here.

01:44.750 --> 01:46.820
So let's run here in the cell

01:49.620 --> 01:57.430
so here we f on the x axis the peak class and on the y axis the sex and actually the color indicates

01:57.440 --> 01:59.840
them the size of each group.

01:59.910 --> 02:07.320
So we can see on the right hand side the color bar and dark color means actually around 100 passengers

02:07.430 --> 02:11.860
in this group and the right color means the 300 plus.

02:11.970 --> 02:18.900
And we can also include here the exact size of each group bypassing the true to the m not meter.

02:20.340 --> 02:23.850
So by doing so we're getting the other numbers.

02:23.850 --> 02:27.070
So this will see the largest group Third Class made.

02:27.480 --> 02:31.140
And two we have three hundred forty seven passengers a..

02:31.200 --> 02:32.640
A bright color.

02:32.640 --> 02:39.950
And that's another pair quite see map and two we can define the color map and actually fly hate map.

02:39.950 --> 02:43.200
The color map red is quite appropriate here.

02:43.560 --> 02:44.510
So let's do this.

02:44.500 --> 02:53.300
What we have here Reds the capital R so here we have red colors and we have dark red for groups that

02:53.310 --> 03:03.230
we have 300 plus passengers and we have bright red for groups that we have around 70 or 100 passengers

03:03.690 --> 03:09.780
and actually we can see here that the scale is not really optimal or perfect yet because here we have

03:09.780 --> 03:11.130
actually one outlier.

03:11.580 --> 03:16.270
So the group a main asset class is by far the largest group.

03:16.470 --> 03:20.670
And the other five groups are pretty much equal here.

03:20.670 --> 03:30.830
So between 76 and 144 and therefore we can cap here our color map for example to 150

03:34.500 --> 03:40.310
so all groups that we have more than one hundred fifty passengers are very dark right here.

03:40.380 --> 03:43.840
And if we can see that we can better differentiate.

03:43.860 --> 03:45.880
The other five groups.

03:45.990 --> 03:50.360
So here we have a very bright color with 76 passengers.

03:50.430 --> 03:54.330
Then we have a darker color with 94 and so on.

03:54.330 --> 03:55.810
So here we have a heat map.

03:55.900 --> 04:01.590
Of the six groups and the color is determined by the size of the groups.

04:01.590 --> 04:06.450
But of course that the color could be also determined by the survival rate.

04:06.450 --> 04:12.600
And again we're using the at the cross tab method and we are splitting our data frame by the sixth column

04:12.600 --> 04:13.850
and the peak last column.

04:14.370 --> 04:20.480
And then we have a look in to the survival column and calculate the mean.

04:20.490 --> 04:24.250
So this is actually the survival rate for all six groups.

04:24.270 --> 04:26.340
So let's calculate this here.

04:26.370 --> 04:33.540
So for example the survival rate for subclass made pairs and justice only 13 percent and the survival

04:33.540 --> 04:38.350
rate for first class female peasant Justice 96 percent.

04:38.370 --> 04:45.390
And again we can pass the cross tabular data to the seaborne heat map and we said to the not pair meter

04:45.390 --> 04:47.900
to true and we want to have four reds.

04:47.910 --> 04:49.080
So let's have a look here.

04:51.830 --> 04:57.670
So here we have our six groups and we can see in dark red color the groups.

04:57.660 --> 05:01.100
That's a high survival rate of around 90 percent.

05:01.100 --> 05:07.250
And and groups with low survival rate are marked with the bright red.

05:07.250 --> 05:11.390
So here we can see the groups made second class and May third class.

05:11.390 --> 05:18.220
Here we have only 40 men 16 percent survival rate and the MFA quite bright color.

05:18.230 --> 05:24.380
All right let's have another example and we can also create a correlation matrix of all numerical features

05:24.380 --> 05:27.280
in our Titanic better frame.

05:27.320 --> 05:32.820
So here we have the correlation matrix and t we have them the animated columns.

05:33.080 --> 05:39.440
So far the correlation to be a failure is between minus 1 and 1 and minus 1 means that perfectly a negative

05:39.440 --> 05:47.110
correlation and plus 1 means perfectly positive correlation and the zero means no correlation.

05:47.270 --> 05:54.110
And we can see that we have a lot of numbers here and it sits at a first glance quite hard to analyze

05:54.110 --> 05:54.350
here.

05:54.350 --> 06:01.490
The correlation matrix and in particular in this case is it makes sense to visualize see the correlation

06:01.490 --> 06:03.780
matrix with a heat map.

06:03.890 --> 06:07.520
So we path a titanic top card to the heat map.

06:07.520 --> 06:12.830
Then again we set an art to true and the color map should be read so again

06:16.090 --> 06:23.500
and here we can see a strong positive correlation in dark red and the negative correlation in bright

06:23.500 --> 06:24.010
color.

06:24.790 --> 06:31.360
So of course in the diagonal we can see perfect positive correlations between the futures itself.

06:31.390 --> 06:33.120
So this is no surprise.

06:33.280 --> 06:36.450
And we can also if I look here at these survived feet.

06:37.120 --> 06:41.220
So we have here a strong negative correlation to the peasant class.

06:41.230 --> 06:46.840
That means first class passengers had a higher chance to survive than a third class passengers.

06:46.850 --> 06:55.660
Then we can see a small negative correlation with the H and the best P features then quite weak positive

06:55.660 --> 07:02.850
correlation with the the pot's feature and a quite significant correlation with the fast feet.

07:03.280 --> 07:08.620
So the higher the ticket price the better the chance to survive the disaster.

07:08.830 --> 07:15.290
And we can see if for example the riders the combination this year between the fair and peak class.

07:15.400 --> 07:22.540
So here we have the most negative correlation and it's no surprise that that between fare and peak class

07:22.620 --> 07:24.850
that's a strong negative correlation.

07:25.180 --> 07:31.720
So passengers in the first class paid more for the tickets than passengers in the third class.

07:31.720 --> 07:38.440
And we can see quite a strong positive correlation between the parts and sip P.

07:38.800 --> 07:46.480
So when passengers traveled with their husband or wife then it was quite likely that also the run also

07:46.480 --> 07:47.460
onboard.

07:47.500 --> 07:53.440
And as a summary we can see here that do we get at our very first glance and intuition on the correlations

07:53.470 --> 07:55.950
without having here a closer look at numbers.

07:55.960 --> 07:58.710
So we can easily see this here graphically.

07:59.260 --> 08:04.900
And this definitely helps if we have fewer even more rows and columns.

08:04.900 --> 08:10.970
So for the human eye some colors are more intuitive than blank numbers here.

08:10.980 --> 08:15.670
All right and with this we are finished here with this video and I hope to see you also in the next

08:15.670 --> 08:16.350
one by.
