‫Now for our next comparison, what we might do is try to combine a couple of independent variables,
‫such as age fell action, which is maximum heart rate, and then compare them to our target variable
‫heart disease.
‫So if we have a look back at our data frame.
‫So what we might compare is age fell ach and target all in one.
‫And now if we go to check our different values for thal act.
‫Now the reason why I know this is max heart rate, because if we come back up in a second so we can
‫see there's a lot of different values here.
‫So the length 91, if you call value counts on any column and the length comes up as something that
‫means that there's that many different values in that column.
‫So what that might be telling us is because there's so many different values, looking at it on a bar
‫graph may not be the best type of graph because if we look at this plot, there's only four columns
‫here and that's pretty interpretable.
‫But when there's 91, that might be a bit harder to look at.
‫So that's where we might bring in something like a scatter graph.
‫Let's go back to our data dictionary and have a look at what Falak is.
‫Come up here.
‫Fell at maximum heart rate achieved.
‫And again, we're really just diving in, reading our data dictionary here.
‫You might just go through different different columns, read them which ones stand out to you and try
‫to compare few of them with the target variable.
‫And remember, if we come back to our data frame.
‫These are often referred to as features or independent variables, and this is often referred to as
‫the target or dependent variable.
‫So that's what we're doing here.
‫We're comparing independent variables to our target variable.
‫This might seem a little as if we're jumping all over the place.
‫And I know I've said this before, it's because we we are we are literally just picking columns here
‫that spark our interest.
‫This one sparked my interest, and we're trying to figure out how they relate to the target.
‫That's what we're doing.
‫You might choose a couple of other columns.
‫I'm just going through the ones that look most interesting to me.
‫So let's make a little heading age verse max heart rate for heart disease, and then we'll turn that
‫into markdown.
‫Beautiful.
‫So to compare three such as age, slack and heart disease, what we might have to do is create a plot
‫with two plots on it.
‫So let's start off first by creating another figure, plot figure, and we'll pass it.
‫A fig size equals ten six.
‫Then we might go scatter, we might do a scatter with the positive examples first.
‫So just bear with me for a second and we'll talk through what's going on while we're while we're going
‫through it.
‫So plot scatter.
‫We want to see on this scatter.
‫The positive examples.
‫So we can go DFA age or DFA age in brackets.
‫They really mean the same thing.
‫But I like to do it this way.
‫Def def don't age.
‫And then in here we're going to do def target equals.
‫Of course you couldn't do this if your column names had spaces in them, but in our case, none of our
‫column names have spaces.
‫What this is doing is a subset of the data set.
‫We're taking the age column from our data frame where this condition equals true, so where the target
‫equals one.
‫So if we did that in a cell below here, def not age, def target equals one.
‫So this is going to show us all the age columns.
‫We're target is equal to one.
‫So that's what we want.
‫Beautiful.
‫And we also want DFL ach, which is maximum heart rate def target equals one beautiful.
‫And we're going to give it a color of salmon.
‫What would this look like if we called that wonderful?
‫So along here we've got maximum heart rate and we got age.
‫So what could you infer from this pretty quickly by just looking at it here?
‫Well, you might infer that there's kind of a downward trend.
‫So if you were to draw a line through there, just a straight line, it's all over the place.
‫Right.
‫But it's kind of you can kind of see the pattern going down here.
‫The younger someone is, the higher their heart rate.
‫That's the kind of trend that you'd be seeing there that makes a little bit of sense right now.
‫These are positive examples.
‫So these are patients because we've got target equals one.
‫These are patients with heart disease.
‫And so now we want the negative examples on the same plot.
‫So scatter with negative examples.
‫I'm going to have plt scatter don't got df don't age.
‫All we're going to do is just copy what we've got above.
‫But except target equals zero because they're negative example this is without heart disease.
‫That lack df dot target equals zero wonderful c equals.
‫I'm going to go light blue.
‫That's the color scheme we're set up for now.
‫Beautiful.
‫So now we've got positive and negative examples on there.
‫And again, they're kind of all over the place.
‫But if you were to look at the trend, the line kind of goes down from both.
‫But again, you can't really split them.
‫This is where our machine learning model will have to take over from our ability to have a look at this.
‫So if you were if you were to look at this now, I just put a semicolon there to stop that little map
‫plot lib output.
‫If you were to look at this and you try to decipher what's going on here, what was the maximum heart
‫rate of of someone who had or didn't have heart disease?
‫The salmon versus blue dots.
‫Blue dots are without heart disease.
‫Salmon are with heart disease.
‫If you had to decipher this, it'd be pretty hard, right?
‫Because these are all so mixed up together.
‫Maybe you might infer that there's some sort of pattern.
‫There's a fair big cluster here.
‫There's a big cluster here.
‫But really, I can't really tell a pattern.
‫Maybe if I had some more time to look at it, I could find something.
‫But this is where machine learning is going to come into play.
‫The patterns that you can't necessarily see straight away machine learning is going to dive into the
‫data.
‫It's going to form some calculations and figure out these patterns that we can't really see.
‫Again, if we had enough time, maybe we'd find something.
‫But when machine learning engineers with data scientists, we prefer that the algorithm does the job
‫for us.
‫So what we might do is add some help for info just to make this plot a little bit more complete.
‫So plot title heart disease in function of age and max hot right then plt dot x label down the bottom
‫is age and then plt dot y label.
‫This is going to be max heart rate.
‫And then we'll add a legend so people can understand which dot is which and they're not just thinking
‫about, well, what's going on here with the salmon and light blue dots, amazing color scheme, but
‫I'm not sure what's what's happening and we'll put the semicolon there instead of there.
‫Wonderful.
‫So that's looking a little bit better.
‫But again, you let me know if you can see some sort of pattern.
‫But to me, all I can really see is a bit of a downward trend.
‫So as someone gets older, their maximum heart rate decreases, which kind of makes sense again.
‫When you're exploring a data set, you won't necessarily always find patterns to begin with.
‫We're just familiarising ourselves with what's going on.
‫And so because we've just done the age, what we might check out is what's the distribution of the age?
‫So to do so, we'll go check the distribution of the age column with the histogram.
‫Now the distribution is another word for spread of the data.
‫So we can kind of see here that there's almost an even spread.
‫So you may recall what kind of distribution and even spread of data has.
‫And if you don't, that's perfectly fine.
‫It took me a while to understand this as well.
‫It took me a long time, actually, and I still have to research.
‫So this kind of distribution here is otherwise known as a normal distribution.
‫And if you were to really say what kind of normal distribution is, we'd look at this perfect normal
‫distribution.
‫Let's have a look.
‫So normal distribution is going to look like a bell curve.
‫To see something like that.
‫So if we come to ours, ours is very close to that shape, but it's kind of swaying towards the ride.
‫So we can see that most of our population or most of our samples, their age is around this big mid
‫gap here.
‫And we don't have that many around the 30 year old age or past.
‫This might be 80 up here or something like that.
‫We don't have many parts there.
‫The majority of our data set are within the 50 to 60 range.
‫And so this is what you might want to do for a bunch of different columns is check the distributions,
‫check the spreads.
‫If we did have someone out here that was like 150, that would maybe be some type of data that we'd
‫have to clean up because I'm not sure if anyone's ever lived to 150 or if we had someone down here that
‫was maybe five or something like that.
‫We'd also have to think about, okay, is that something we want to include in our data set?
‫But this is going to be different column to column.
‫So we're just checking the age here.
‫It's a normal distribution.
‫We might do the same for other columns, but the way you sort of think about samples out here is the
‫referred to as outliers.
‫And now how will you tell that if there's any outliers?
‫Well, distribution plot, this histogram is one of the best ways to do it.
‫So if you're getting some weird results, like some weird results in terms of your machine learning
‫models later on, it may be because there's outliers in the data, and that's where you'll have to check
‫different distributions of each columns.
‫So that's one way to do it.
‫Now what we might do is compare another two columns.
‫So if we come up here to our data dictionary, I saw this one before the chest pain type.
‫And I thought that would be interesting to see.
‫So if we got here for different types of chest pain, so chest pain related, decreased blood supply
‫to the heart, chest pain not related to typically esophageal spasms.
‫So I guess that's like your esophagus, which is, I think that tube from your mouth to your stomach
‫or something like that.
‫Asymptomatic chest pain, not showing signs of disease.
‫Okay.
‫So this will be pretty interesting, right, if we compare this to the Target column.
‫So chest pain versus target.
‫So does chest pain relate to whether or not someone has heart disease?
‫So let's come down here.
‫Well, go make a little heading.
‫Heart disease.
‫Frequency per.
‫Chest pain type.
‫What we might do, actually, is just remind ourselves, copy our data dictionary for chest pain so
‫we can remember what each different value is.
‫So if we come in here.
‫And we'll copy this.
‫Shifting into will bring it down and we'll paste it here.
‫Wonderful.
‫So this is what we're going to compare.
‫We can do that with a fairly quickly with a cross tab.
‫Def don't see p.
‫Def not target.
‫Okay.
‫So if we look at this, what would we devise in here?
‫Hmm.
‫It seems as chest pain goes up.
‫So does whether they have heart disease.
‫But if we get zero chest pain.
‫There's a lot more that don't have heart disease than do.
‫But if we get to there's only 18 with zero so don't have heart disease but 69 so nearly over three times
‫the amount that do have heart disease.
‫So this is non adrenal pain typically.
‫Oh non heart related.
‫Well that's that's interesting that it's non heart related.
‫So these are the type of patterns you'll start to find out in your data.
‫Some make sense.
‫That doesn't really make sense to me.
‫Non heart related pain.
‫Yet more people have heart disease with two than not.
‫And so these are the type of things you might be wanting to discuss with a subject matter expert.
‫If you're looking through a data set such as us looking through this heart disease data set, and I'm
‫not a doctor, I'm not trained medically, I've researched some things about health, but I've nothing
‫no idea about chest pain.
‫So if I got this data set off someone from a medical profession, I'm trying to use machine learning
‫to figure out whether someone has heart disease or not.
‫And I'm coming across these patterns that I don't really understand.
‫That's where I'd probably reach out and go, Hey, so in Medical Professional or I do my own research,
‫such as looking up what these actually mean, we did that before defining angina going, Hey, I'm seeing
‫this in the data, but can you shed some light?
‫It's kind of confusing to me.
‫Is this correct?
‫Is this not that's the kind of the insights that we're looking for is both patterns that make sense
‫to us, such as the normal distribution of age, such as the declining max heart rate.
‫As someone gets older, this one maybe doesn't make as much sense.
‫Is heart disease more prevalent in women than it is males?
‫So this is the type of questions that we're trying to get.
‫We're trying to formulate an idea in the data by not finding answers, but finding questions that we
‫can ask.
‫And so what we might do is make this a little bit more visual as we've done before.
‫Make the cross tab more visual.
‫Paid a cross tab df not c p df dot target.
‫We're just writing what we've got above there.
‫Dot plot, same plot.
‫Again, we might do a bar because there's four different values here versus two different values there.
‫So we should be able to look at it fine on a bar graph, fig size equals ten and six.
‫Wonderful.
‫And we're going to use our favorite colors.
‫Color equals.
‫What are we using?
‫Light blue salmon.
‫Actually, I think the order was the other way around.
‫Then we did salmon first, then light blue doesn't really matter.
‫Beautiful.
‫And we're going to add some add some communication plus title.
‫Heart disease frequency per chest pain type.
‫Then we got a plt x label.
‫We're going to do chest pain type.
‫And then on the y is plt y label amount.
‫Beautiful plt legend.
‫We're going to put on here.
‫No disease.
‫Disease.
‫And then we'll finish it off with again, we're going to make sure that the X ticks are vertical so
‫it's a bit easier to read.
‫Shifting into what do we got?
‫PY plot has nothing y label.
‫We've got a little typo.
‫Beautiful.
‫There we go.
‫So that's a bit more visual.
‫So then we're just turning our cross tab into a graph here.
‫Now, this is something that we could take pretty quickly to someone and go, Hey, what's going on
‫here?
‫Chest pain type has way more accounts with the disease than chest pain to that is.
‫And it's supposed to be non and general pain.
‫So typically esophageal.
‫That word is very hard for me to pronounce.
‫Esophageal spasms, non heart related.
‫So this is again raising questions from the data.
‫That's what we're trying to do in this exploratory data analysis.
‫All right.
‫So we've got a pretty visualization there.
‫What we might do next is check out the correlation between independent variables and our dependent variable.
‫So again, if we have a look at our data frame, this is what you want to be jumping in out of, right?
‫Just using DF had to quickly have a snapshot of your data frame.
‫These are our independent variables remind ourselves and we're trying to use them to predict target.
‫So we'll see how we can compare those and we're going to use a correlation matrix, but we'll see that
‫in the next video.