‫Beautiful.
‫Now, I found out a little bit more about our dataframe.
‫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, right?
‫It's going to search through the different columns of our DataFrame 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 six.
‫So this is what we want to do.
‫We want to compare.
‫The six attribute.
‫To the target attribute.
‫So what we might do is go do six 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 is zero here.
‫That number and male is one reason why I know that is if we go back up to our data dictionary.
‫If we look here, sex one equals male, zero equals female.
‫Wonderful.
‫So we come down.
‫So we know our data set is a little bit tilted towards having more males and females.
‫If we wanted to compare the sex column to the target column.
‫A handy function in pandas is the PD cross tab.
‫So let's have a look at that.
‫Compare Target column with six column Patty Cross tab.
‫We're going to pass at DF Target with DF dot six.
‫Beautiful.
‫So this is going to 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 heuristic.
‫So since there are about 100 women, right, if we add up this, so we would see sex is zero.
‫And this is comparing the target column to the sex column.
‫So since there are about 100 women and 72% of them or 72 out of out of the entire amount of women,
‫have a positive view of heart disease being present.
‫So see here, the target is one.
‫So that means an indication that they do have heart disease when 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, there'd be roughly a 75% chance she has heart disease.
‫The 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 data set, 75% 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 then 93 target equals one.
‫When sex equals one when the sample is a male, 93 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% plus 50% over 100.
‫You get about 62.5% 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 data set.
‫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 set.
‫And based off this comparison alone, we might infer that there's a 62.5, remember about 75% if there
‫are women and 50% if they're a mouse or we're just adding them together and averaging them.
‫So 62.5% 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 we're doing the sex feature, the sex column, we're comparing it to Target.
‫So if we would just use that one feature alone.
‫If we expect a patient to come to us, we'll go.
‫Okay.
‫Any patient at all?
‫There's a 62.5% 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.
‫And so what we might do is make this a bit more visual, create a plot of cross tab.
‫We've got paid a cross tab df dot target df sex 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.
‫We'll go ten six.
‫So that's width and height there, and then we'll give it our famous colour that we're going to work
‫with, which is we'll do salmon.
‫And light 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, we've got Target, which is zero, not heart disease, and this is sex zero one.
‫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, and the salmon colour is female.
‫If we compare these columns, we can see that the females who do have heart diseases 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 plot title, heart disease.
‫Frequency for six and then we go plt dot maybe we add an x label and we go zero equals no disease,
‫one equals disease.
‫We might go plot y label.
‫We might put a mount here.
‫Then maybe a legend because might change this legend.
‫So if we can update that to rather than being zero one so we want to communicate this to someone.
‫We're doing some data analysis.
‫We want to they don't know what zero one means.
‫So we want to do 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?
‫Oh, I forgot, 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 might 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 design it 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.
‫Now that we've compared two 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 on what we've gone through here.
‫Maybe try and 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.