Naive Bayes Part 9 | Handling Numerical Data — Transcript
Full transcript
- 0:01So hi, if we've noticed so far,
- 0:02whenever we talk about Naive Bayes, we
- 0:05are continuously talking about
- 0:07categorical data. Right? In all the
- 0:09examples we did in the previous videos,
- 0:12every column was categorical. So, if
- 0:15instead of a categorical column, we
- 0:18have a numerical column, how will our
- 0:20Naive Bayes work? That's what we will
- 0:23see in this video. Okay? So let's say I
- 0:26have this data. There are three columns
- 0:29: height, weight, and gender. Height is
- 0:31in centimeters, weight is in pounds,
- 0:33and gender is male or female. Alright?
- 0:36So this is the input I have as data.
- 0:41And now my task is to create a
- 0:43predictor, a machine learning model,
- 0:45which can predict the gender of a new
- 0:47incoming data point. Like, if I am
- 0:51asked, if the height is 185 and the
- 0:54weight is 170, then I have to find out
- 0:57what the gender of this human being is.
- 1:00Or what is the gender of this person?
- 1:01Alright? So this is the problem
- 1:03statement, and again, we are going to
- 1:05use Naive Bayes. So, let's formulate
- 1:08the problem first. So, obviously, if
- 1:11you want to find out, if you have to
- 1:14formulate this, you have to basically
- 1:17find out the probability of this guy or
- 1:20girl being a male given height is equal
- 1:23to 185. And this is intersection weight
- 1:30is equal to 170. We have to find this.
- 1:34Right? And by the formula, you already
- 1:39know, to calculate this, you will have
- 1:43to find the probability of h = 185
- 1:47given male, multiplied by the
- 1:51probability of weight = 170 given male,
- 1:56and then you have to find the
- 1:59probability of being male. Right? We
- 2:03will have to calculate these three
- 2:05things. We have to calculate three
- 2:06probabilities. Similarly, we will also
- 2:09have to find out the same thing for
- 2:12being female. Right? So this is known.
- 2:15Alright? Now we have to find this, this
- 2:18, and this. To be honest, if you talk
- 2:21about this term. It is very simple.
- 2:25What is the probability of male? In my
- 2:26data. So you can see there are a total
- 2:28of eight data points, out of which four
- 2:30are male. So this will directly be 1/2.
- 2:34This is 1/2 directly, right? The rest
- 2:37is to find this and this, right? In
- 2:40categorical data, it's easy, right? We
- 2:43would separate and count them, but here
- 2:46you can notice that 185 is not anywhere
- 2:48in my entire data point. So if I have
- 2:51to find the probability of height, that
- 2:53means, basically, now I just have to
- 2:55focus on these four data points. In
- 2:58this, I want to ask, what is the
- 3:00probability of the height being 185
- 3:02among these four? If you focus on these
- 3:04four, on the height, there is not a
- 3:06single data point whose probability is
- 3:08185, so obviously this term will become
- 3:10zero. Right? Similarly, this term will
- 3:12also become zero and then this entire
- 3:13probability will become zero. So what
- 3:15is the solution for this? You take an
- 3:17assumption. Okay? So, the assumption is
- 3:21this, the assumption is that the height
- 3:28is a Gaussian distributed random
- 3:37variable. This is the assumption. Okay?
- 3:43So, what are we assuming? That ignore
- 3:46the female part for now. Okay? Ignore
- 3:48the female ones. Let's focus on the
- 3:50male. So here, we will assume that
- 3:55these four data points, these four data
- 3:57points, they follow the normal
- 3:59distribution. I hope you remember the
- 4:04normal distribution, this distribution,
- 4:06we will assume that this is a normal
- 4:09distribution. Okay? Now what we will do
- 4:13is we will first calculate the mean and
- 4:19standard deviation of these points,
- 4:21wherever there is a male, for those
- 4:24data points on the height column, I
- 4:26will find out the μ and σ, right,
- 4:28which is the standard deviation. Okay?
- 4:32Now I know this, I, I am removing this.
- 4:35We already know the formula for normal
- 4:40distribution to find out the
- 4:43probability of a particular data point
- 4:48happening is this 1/σ √2π e to the
- 4:56power -1/2 (x-μ/σ) whole square.
- 5:05Right? Now in this equation, if you see
- 5:09, if I have μ, as in I have the mean,
- 5:12and I have σ, as in I have the
- 5:15standard deviation, and I have x, which
- 5:18is this number, then I can easily find
- 5:21out the probability of finding x. Right
- 5:26? It will be some probability. Right?
- 5:28And this is the probability that needs
- 5:31to be calculated. Right? We will repeat
- 5:35the same work on the weight column.
- 5:37Okay? So what will we do? Again, we
- 5:39will assume that the weight column is
- 5:42also normally distributed. Okay? Again,
- 5:46we will find the μ and σ for this
- 5:48column wherever the gender is male.
- 5:51Okay? As soon as this comes, we will
- 5:53again put these three things into this
- 5:55formula. μ, σ, and x, right? And we
- 6:00will again get the probability of
- 6:02finding 170 in this data. Right? And
- 6:05then we will put it here. And we will
- 6:09multiply these three terms. We will get
- 6:11some probability, let's say. And
- 6:14similarly, we have to do the same work
- 6:16for the female. Exactly the same. So
- 6:21the only difference this time around
- 6:23would be. The only difference will be
- 6:27that now you focus on the data below,
- 6:28where it's female. Again, you will
- 6:31assume it's normally distributed. You
- 6:33calculate μ and σ. You calculate this
- 6:35value, put it here, okay? And same with
- 6:37this one, Right? And that is how it is
- 6:43done, okay? Now you might have this
- 6:46doubt, you could ask, but what if this
- 6:49assumption is wrong and it's not
- 6:51normally distributed, right? So, by the
- 6:55way, the technique we just used, we
- 6:57call it Gaussian. Gaussian Naive Bayes.
- 7:04In Scikit-learn, there is a class for
- 7:06this directly, you can use it directly,
- 7:08okay? Yeah, so coming back to your
- 7:10question, you can have this question
- 7:12that, what if this data is completely
- 7:14different from normal, or not normal at
- 7:16all, okay? In that case, what can you
- 7:19do? To be honest, the right approach
- 7:22would be to first plot the distplot to
- 7:24check how the data is distributed.
- 7:27Right? And then you can change your
- 7:29assumptions. You can either go with
- 7:32Gaussian Naive Bayes. If you feel it's
- 7:35close to normal. If it's not, there are
- 7:38various other distributions. It could
- 7:42be binomial. So you will use the
- 7:46binomial formula. And you call it
- 7:51binomial like this. Or you can use the
- 7:53Multinomial Naive Bayes. You can also
- 7:59use the Complement. Naive Bayes, right?
- 8:04So for different distributions, you
- 8:06will know the formula for each because
- 8:08everyone has a formula. You just have
- 8:11to find out the distribution and you
- 8:13just have to see which one it is close
- 8:14to. And then, by applying that
- 8:17particular distribution's formula, you
- 8:20can apply Naive Bayes. Right? That is
- 8:22the correct approach. But since it was
- 8:25easy to explain, I explained the entire
- 8:27thing using Gaussian Naive Bayes. Okay?
- 8:30So I hope this whole video is clear.
- 8:32Now in the next video, I will take the
- 8:34Iris dataset. Where all the columns are
- 8:37numerical and I will demonstrate
- 8:38applying these same steps on it. Okay?
- 8:42So thanks for watching.
About this transcript
This page contains the full transcript of Naive Bayes Part 9 | Handling Numerical Data by CampusX, generated from the public captions YouTube serves with the video. The transcript has 1,206 words across 173 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.