Beautiful.
Now I found out a little bit more about our data frame what we're going to do now is compare different
columns to each other.
And the reason being here is because this is helpful to help us start gaining an intuition about how
the features.
So these columns here relate to the target variable.
So that's what our machine learning model is eventually going to do.
Ryan it's going to search through the different columns of our data frame and then figure out the patterns
as to what target value is associated with values here.
Now we could do much the same if you just went through this row by row you would start to gain an intuition
about what values associate with what target value.
But let's stop talking about it.
Let's visualize it.
So what we'll do the first two columns we might compare our age to target.
So we go here frequency according to sex.
So this is what we want to do we want to compare the sex attribute to the target attribute.
So what we might do is go into sex dot value counts here.
There's no real pattern of how we're doing this.
We're just kind of exploring the data.
All right.
So we see here there's a lot more male to female.
So female 0 here.
That number and male is one reason why I know that is if we go back up to our data dictionary we look
here sex 1 equals male 0 equals female.
Wonderful.
So it come down.
So we know our dataset is a little bit tilted towards having more males and females.
If we wanted to compare the sex column to the tiger column a handy function in pandas is the PD dot
cross tab.
So let's have a look at that.
Compare target column with sex column Patty cross tab we're going to pass it DFT at Target with the
F dot six beautiful.
So this is gonna give us some information here.
What can we infer from this.
Well what we could do to begin with before we even build a single machine learning model is make a simple
her mistake.
So since there are about 100 women right.
If we add up there so we see sex is zero.
And this is comparing the target column to the sex column.
So since there are about 100 women and 72 percent of them or 72 out of out of the entire amount of women
have a positive value of heart disease being present.
So see here the target is 1.
So that means an indication that they do have heart disease or we might infer based on this one variable
if the participant is a woman.
So if the sample if we come back up here if the sample in our data is a woman they'd be roughly a 75
percent chance.
She has heart disease reason being is because here we've taken about 100 or so again we're just rounding
here.
And if we add these up that's going to equal 96.
But if we see here just looking at this just looking at this comparison between sex and target 72 out
of 96.
So basically 75 out of 100.
So what we're inferring from this before we even build a single machine learning model.
If a woman comes and we're trying to figure out whether she has heart disease or not based on our existing
data based on our existing dataset 75 percent chance that she has heart disease.
Again remember based on our existing data set it might be different in the real world.
And so if we look at male there's about 200 in total with around half indicating a presence of heart
disease.
So see there 93 target equals one sex equals 1 when the sample is a male ninety three out of 207 indicate
that there is heart disease.
So if we looked at this if the participant is male we might predict around half the time that participant
will have heart disease.
And then if we average these out we'd get 75 percent plus 50 percent over 100 and you get about 60 2.5
percent chance that anyone.
Of course this is always based on our existing data because that's the only patterns that we can find
is with the data that we have.
So based on our existing dataset this up here if we were to see a random patient we're making our decisions
whether that random patient a new patient we haven't seen before.
We're making our decisions based on our existing data said and based off this comparison alone we might
infer that there's a sixty two point five.
Remember about 75 percent if they're are women and 50 percent of their male.
So we're just adding them together and averaging them so sixty two point five percent chance that they
have heart disease.
Now this is our very simple baseline.
And what we're trying to do here is just form an intuition in our head about the data set about how
different features in this case were doing the sex feature the sex column we're comparing it to target.
So if we would just use that one feature alone we would expect the patient to come to us we'll go okay
any patient at all.
There's a 60 2.5 percent chance that they have heart disease and now with that baseline what we're going
to try and do is beat it using machine learning.
So again if this is a little bit confusing don't worry it's a little bit confusing when I first started
figuring out patterns.
But the main thing to remember is all we're doing is just creating an intuition.
We're becoming subject matter experts on the data or at least trying to.
So what we might do is make this a bit more visual create a plot of cross tab paid dot cross tab the
F Doc target the F six and then we can go dot plot and we'll do it as a kind of bar we'll give it a
fig size just because we want it to come out and go 10 6.
So that's width and height there and then we'll give it our famous color that we're going to work with
which is Andrew Salmon and like Blue Wonderful beautiful.
So this is another visualization that we can start to get an idea.
And it shows it a little bit more intuitively than just a cross tab.
So if we look here you've got target which is zero not heart disease.
And this is sex 0 1.
So we can see that the people who don't have heart disease there's far more male.
And we can see here that the people who do have heart disease now there are more males that do have
heart disease.
But if we look at the ratios compared to each column.
So this one is male.
Blue is male.
Then there's salmon color is female.
If we compare these columns we can see that the females who do have heart disease is about a 3 to 1
if you would just compare those visually that 3 to 1.
Right.
So that's where we're getting a three and four chance of a female at random having heart disease but
males the ratio is kind of and it's definitely not completely even.
But it's a lot closer than what the females are.
Wonderful.
So if we wanted to add some titles to this we could we could add some communication here such as maybe
we go BLT title.
Heart disease
frequency for sex and then we go P. BLT dot maybe we add an x label and we go zero equals no disease
1 equals disease and then we might go plot y label might put amount here then maybe a legend might change
this legend.
So if we can update that too.
Rather than being 0 1 so we want to communicate this to someone we're doing some data analysis we want
to they don't know what 0 1 means we wanted to female male actually I'll show you what this does.
Before we even do it so let's do that.
We'll add a little semicolon here so we get rid of that.
What are we missing out here.
We got legend
that should work.
Wonderful.
So that's a little bit more intuitive.
And so this is what I wanted to change here I wanted to get them vertical.
So what we do is plot x ticks.
These are X ticks here little ticks that are labeling.
So we go plot x ticks and then rotation equals zero.
This took us a little while to get set up but really if you're going through this you might breeze through
it if you're going through it by yourself.
But if we want to communicate it with someone else we better designed in this way because we may know
the data ourselves but if we just want to share this image so someone else has an intuition over the
comparison of who has heart disease depending on what sex they are they won't know what we know with
the data.
So that's why we're making our visuals as communicative as possible.
All right.
Well now that we've compared to columns we've seen how to do it what we're going to do in the next few
videos is compare a few more.
So take a little break.
Reflect back on what we've gone through here and maybe try to compare two columns of your own.
Usually you can pair the target with a single column here and you start to work out the patterns.