Latest / CyberSecurity Summary / Statistics for Machine Learning: Implement Statistical methods used in Machine Learning using Python
Transcript
- 0:00Speaker 1: Welcome to the deep dive. You know, when most people
- 0:03Speaker 1: hear machine learning or maybe AI, I think the first
- 0:07Speaker 1: thing that comes to mind is the code.
- 0:10Speaker 2: Right, Oh, absolutely, Python, scripts, neural nets, all that complex
- 0:13Speaker 2: engineering stuff. That's the flashy part.
- 0:15Speaker 1: Yeah, the engine, It is the engine. Yeah.
- 0:17Speaker 2: But what our source material for today really emphasizes, and
- 0:19Speaker 2: it's looking specifically at the prerequisites for even building those engines,
- 0:24Speaker 2: is that the real foundation. It isn't the code, ok,
- 0:28Speaker 2: it's math specifically, it's statistics. You could almost call it
- 0:32Speaker 2: a preliminary requirement.
- 0:33Speaker 1: Right. So that's our mission today. Then we're aiming to
- 0:35Speaker 1: give you a bit of an intellectual shortcut here. We
- 0:38Speaker 1: want to pull out the essential statistical concepts that the
- 0:41Speaker 1: core of vocabulary and the toolkit you need for exploring data,
- 0:45Speaker 1: cleaning it up, getting ready for predictive modeling.
- 0:48Speaker 2: Basically saving you the trouble of reading the whole textbook page.
- 0:51Speaker 1: By page exactly. This is about getting that statistical fluency
- 0:54Speaker 1: you need before you even think about training.
- 0:56Speaker 2: A model, and it's not just about passing some exam.
- 1:00Speaker 2: You genuinely need these concepts because well, every single step
- 1:05Speaker 2: in an mL pipeline from the moment you get the
- 1:07Speaker 2: data to evaluating how well your model did. It's fundamentally
- 1:11Speaker 2: a statistical operation.
- 1:13Speaker 1: Okay, so where do we start. I guess right at
- 1:15Speaker 1: the beginning, recognizing what kind of data you're even dealing with.
- 1:20Speaker 2: That's the spot the sources remind us that data collection
- 1:23Speaker 2: isn't just you know, chaos. It's usually driven by trying
- 1:26Speaker 2: to answer some real world question.
- 1:28Speaker 1: Like market research before you launch a product, maybe.
- 1:31Speaker 2: Exactly is this product feasible? Who are we trying to
- 1:33Speaker 2: reach that kind of thing?
- 1:34Speaker 1: And the answers we get the actual numbers we collect
- 1:37Speaker 1: in store.
- 1:38Speaker 2: Those are grouped into what statisticians call random variables. They're
- 1:41Speaker 2: the numerical backbone of whatever research you're doing.
- 1:44Speaker 1: Okay, random variables, So how do we bring some order
- 1:47Speaker 1: to that? How do we structure them?
- 1:49Speaker 2: Well, we mainly split them based on what they can
- 1:52Speaker 2: actually measure. First up, you've got discrete random variables.
- 1:55Speaker 1: Discrete meaning separate.
- 1:57Speaker 2: Yeah, I think fixed counts. They have to be whole numbers.
- 1:59Speaker 2: It can't be like counting how many people clicked on
- 2:03Speaker 2: an ad or the number of gold medals a country
- 2:05Speaker 2: one in the Olympics. Not it fixed counts, Definite fixed counts.
- 2:09Speaker 1: So what's the other kind the stuff that isn't fixed counts?
- 2:12Speaker 2: That would be your continuous random variable. This one stores
- 2:15Speaker 2: values that can be decimals or floats, and theoretically, at
- 2:19Speaker 2: least you could measure them with infinite precision.
- 2:22Speaker 1: Like height or weight.
- 2:24Speaker 2: Perfect examples height, weight, temperature. You can always, in theory,
- 2:29Speaker 2: add another decimal place to make the measurement finer.
- 2:31Speaker 1: Okay, that makes sense for numbers, But what if the
- 2:35Speaker 1: data isn't a number at all, Like if it's just
- 2:37Speaker 1: a label someone's city or maybe their preferred brand.
- 2:40Speaker 2: Ah, good question. Then you're working with categorical variables. And
- 2:44Speaker 2: this is where we need another layer of distinction, because
- 2:47Speaker 2: how an mL algorithm handles these depends a lot on
- 2:51Speaker 2: whether the categories have some kind of internal meaning or order.
- 2:54Speaker 1: Wait, internal meaning? Why does that matter? Isn't red just
- 2:57Speaker 1: red to a computer?
- 2:59Speaker 2: It matters quite a bit, actually, mostly because it impacts
- 3:02Speaker 2: how you encode that data before feeding it to a model.
- 3:06Speaker 2: If the categories have absolutely no inherent rank or order,
- 3:11Speaker 2: we call them nominal variables. Okay, think gender like male female,
- 3:16Speaker 2: or maybe types of fruit apple, banana, orange. You can't
- 3:19Speaker 2: really rank one above the other. Logically, they're just distinct groups.
- 3:23Speaker 1: Right, distinct groups makes sense, But what if they can
- 3:26Speaker 1: be ranked and it's.
- 3:27Speaker 2: An ordinal variable. Think about say a customer satisfaction rating low, medium, high.
- 3:33Speaker 1: Ah, Okay, there's a clear hierarchy.
- 3:35Speaker 2: There exactly, And knowing this difference is key before you
- 3:38Speaker 2: start your future engineering phenomenal variables. The algorithm often needs
- 3:42Speaker 2: to treat each category as totally separate, maybe using something
- 3:46Speaker 2: called one hot encoding. But for ordinal variables you might
- 3:49Speaker 2: be able to use encoding methods that preserve that ranking,
- 3:52Speaker 2: which can sometimes make the model simpler or even more accurate.
- 3:56Speaker 2: So yeah, knowing this distinction is pretty fundamental.
- 3:59Speaker 1: All right, So we figure fur out what kind of
- 4:00Speaker 1: variables we have. What's the immediate next step? Usually it's
- 4:04Speaker 1: descriptive statistics, right, trying to summarize potentially huge data sets.
- 4:09Speaker 2: Yes, exactly. We're moving from just defining things to actually
- 4:12Speaker 2: starting to tell the story hidden the data. The first
- 4:15Speaker 2: step is usually summarizing it, focusing on its center and
- 4:18Speaker 2: it's spread.
- 4:19Speaker 1: Okay, center and spread. Let's start with the center. Measures
- 4:22Speaker 1: of central tendency is that the term that's the one and.
- 4:24Speaker 2: The big three here are the mean the median and
- 4:27Speaker 2: the mode.
- 4:28Speaker 1: Everyone knows the mean the average, Right, add them all up,
- 4:31Speaker 1: divide by how many there are. Seems simple, But what's
- 4:34Speaker 1: the specific mL insight? Why is it so important?
- 4:37Speaker 2: Well, mathematically, the mean is the center of balance for
- 4:41Speaker 2: your data. But what's really interesting is how it connects
- 4:44Speaker 2: directly to prediction. How So, when you build, say a
- 4:47Speaker 2: simple linear regression model, what you're essentially doing is trying
- 4:51Speaker 2: to draw a line that minimizes the square distance between
- 4:54Speaker 2: that line and all your data points. Yeah, the mean
- 4:57Speaker 2: turns out to be the single value that inherent only
- 5:00Speaker 2: minimizes that scored error.
- 5:02Speaker 1: Huh. So it's like the best guess if you knew
- 5:05Speaker 1: nothing else.
- 5:06Speaker 2: It's the optimal point prediction if you had zero other information. Yes,
- 5:09Speaker 2: it's a point of minimum error.
- 5:11Speaker 1: Okay, but the mean has that famous weakness, right, the
- 5:15Speaker 1: outlier problem. Like if your averaging salary is in a
- 5:18Speaker 1: small startup and suddenly the CEO's twenty million dollars salary
- 5:21Speaker 1: gets added.
- 5:22Speaker 2: In exactly that one massive outlier just yanks the average
- 5:26Speaker 2: way way up, making it not very representative of the
- 5:30Speaker 2: typical employee.
- 5:31Speaker 1: So that's where the medium comes in.
- 5:32Speaker 2: Precisely, The median is the exact middle value when you
- 5:36Speaker 2: sort your data from smallest to largest. Fifty percent of
- 5:38Speaker 2: the data is below it, fifty percent is above it.
- 5:40Speaker 1: And because it only cares about the middle position.
- 5:43Speaker 2: It's incredibly robust to those extreme outliers. That twenty million
- 5:46Speaker 2: dollars salary doesn't really affect the median much, if at all.
- 5:50Speaker 1: And if you have an even number of data points,
- 5:53Speaker 1: no single middle value.
- 5:54Speaker 2: Simple you just take the average of the two middle values.
- 5:57Speaker 2: Still gives you that robust central point.
- 5:59Speaker 1: Okay, so mean is air minimizing, but sensitive to outliers,
- 6:03Speaker 1: meeting is robust. What about the third one, the mode?
- 6:05Speaker 2: The mode is even simpler. It's just the value that
- 6:09Speaker 2: shows up most often in your data set, most frequent yep.
- 6:12Speaker 2: It's typically most useful for categorical data, finding the most
- 6:16Speaker 2: popular choice or the most common group.
- 6:18Speaker 1: And he quirks with the mode.
- 6:20Speaker 2: Couple interesting ones. It's the only measure of center that
- 6:23Speaker 2: might not actually be present in your data, which sounds
- 6:26Speaker 2: weird but can happen. And you can also have more
- 6:28Speaker 2: than one mode, like bimodal exactly by moodal if there
- 6:32Speaker 2: are two peaks, or even multimodal that can be a
- 6:35Speaker 2: clue that your data might actually be composed of a
- 6:37Speaker 2: couple of different underlying groups or clusters.
- 6:39Speaker 1: Okay, so we found the center using mean, median or mode.
- 6:43Speaker 1: But you said center alone isn't enough. Two data sets
- 6:47Speaker 1: could have the same mean but look totally different.
- 6:50Speaker 2: Right. Imagine one data set clustered tightly around the mean
- 6:54Speaker 2: and another spread way out, same mean, very different story.
- 6:57Speaker 2: That's why we need measures of disperge or spread, and
- 7:01Speaker 2: the main ones are variance in standard deviation STY.
- 7:04Speaker 1: Okay, variance and STY. They both measure spread, right, how
- 7:07Speaker 1: far data points tend to be from the center, usually
- 7:09Speaker 1: the mean.
- 7:10Speaker 2: That's the core idea. A high value for either variants
- 7:13Speaker 2: or SD means the data is really spread out, dispersed widely.
- 7:18Speaker 2: A small value means everything's huddled close to the mean.
- 7:21Speaker 1: So if they measure the same basic thing, why do
- 7:24Speaker 1: we need both? What's the practical difference, especially thinking about
- 7:27Speaker 1: machine learning?
- 7:28Speaker 2: Okay, so mathematically, the standard deviation is just the square
- 7:32Speaker 2: root of the variance. The absolute key difference is the
- 7:35Speaker 2: units units. Yeah, variance is calculated using square differences, so
- 7:39Speaker 2: it's units are the square of the original data's units.
- 7:43Speaker 2: If you measure at height in meters, the variance is
- 7:45Speaker 2: in meters squared, which is kind of awkward to interpret directly.
- 7:49Speaker 1: Not very intuitive.
- 7:50Speaker 2: But the standard deviation, because it's the square root, is
- 7:53Speaker 2: back in the original units. So if your height data
- 7:55Speaker 2: is in meters, the SD is also in meters.
- 7:58Speaker 1: Ah. Okay, so s D is easier to compare directly
- 8:01Speaker 1: to the mean.
- 8:02Speaker 2: Much easier. It makes SD far better for interpretation, for reporting,
- 8:06Speaker 2: and really crucially for something called feature scaling or normalization
- 8:10Speaker 2: in mL.
- 8:10Speaker 1: Why future scaling.
- 8:11Speaker 2: Well, often in mL you have features measured on totally
- 8:14Speaker 2: different scales, maybe aging years, income in thousands of dollars,
- 8:18Speaker 2: heightened centimeters. Models can sometimes struggle with that or give
- 8:21Speaker 2: too much weight to features with larger numerical values.
- 8:24Speaker 1: So you need to put them on a level playing
- 8:26Speaker 1: field exactly.
- 8:27Speaker 2: You often rescale features so they have a mean of
- 8:29Speaker 2: zero and a standard deviation of one, And standard deviation
- 8:33Speaker 2: is the metric you use to do that rescaling properly.
- 8:35Speaker 2: It's fundamental for pre processing data for many algorithms.
- 8:39Speaker 1: Okay, we've gone from defining data types to summarizing them
- 8:43Speaker 1: with center and spread. Now how do we pivot towards
- 8:46Speaker 1: using this data for prediction. That feels like the next
- 8:49Speaker 1: logical step.
- 8:50Speaker 2: It is, and that pivot really starts by defining a
- 8:53Speaker 2: potential cause and effect relationship. This is where we introduce
- 8:57Speaker 2: the concepts of dependent and independent.
- 8:59Speaker 1: Variable right setting up the experiment.
- 9:01Speaker 2: Essentially, pretty much, we're defining our modeling goal. What factor
- 9:05Speaker 2: are we changing or observing the independent variable, and what
- 9:10Speaker 2: outcome are we measuring the effect on the dependent variable.
- 9:14Speaker 1: So the independent variable is the input, the thing we control,
- 9:18Speaker 1: or the factor we think is causing a change.
- 9:20Speaker 2: Exactly like in a drug trial, the dosage level would
- 9:23Speaker 2: be the independent variable. Or using an example from the source,
- 9:27Speaker 2: maybe the type of pitch a pitcher throws to a batter.
- 9:29Speaker 2: That's the input being.
- 9:30Speaker 1: Varied, and the dependent variable is the output the result
- 9:33Speaker 1: What happens because of the independent variable.
- 9:35Speaker 2: Yes, it's the variable being tested or measured that responds
- 9:38Speaker 2: to the changes. In that baseball example, the batter's performance,
- 9:42Speaker 2: did they hit it how well? That's the dependent variable.
- 9:45Speaker 2: Its value depends on the pitch type.
- 9:47Speaker 1: And getting these two defined correctly seems absolutely critical. It's
- 9:50Speaker 1: basically framing the entire problem you want your mL model
- 9:54Speaker 1: to solve.
- 9:55Speaker 2: It is you're specifying the relationship you intend to model
- 9:58Speaker 2: and predict.
- 9:58Speaker 1: Now, underpinning all all of this statistical analysis, all these
- 10:02Speaker 1: measurements and relationships, there's a really core principle that gives
- 10:05Speaker 1: us confidence in the results, right, the law of large
- 10:08Speaker 1: numbers LLLN.
- 10:09Speaker 2: Ah. Yes, the LLN. It's absolutely fundamental. It's kind of
- 10:12Speaker 2: the bedrock that makes statistics work reliably.
- 10:15Speaker 1: So what is its state? In simple terms, it.
- 10:17Speaker 2: Basically says that if you repeat the same experiment over
- 10:21Speaker 2: and over and over again a huge number of times,
- 10:23Speaker 2: the average of the results you get will get closer
- 10:26Speaker 2: and closer to the true expected theoretical value.
- 10:30Speaker 1: Like flipping a coin.
- 10:31Speaker 2: Perfect example, flip a coin just ten times, you might
- 10:34Speaker 2: easily get say seven heads and three tails. That's pretty
- 10:38Speaker 2: far from the expected fifty to fifty, right, But flip
- 10:40Speaker 2: that same coin a million times or ten million times,
- 10:44Speaker 2: the ratio of heads to tails is going to get
- 10:46Speaker 2: incredibly close to exactly one to one. It converges on
- 10:49Speaker 2: the true probability.
- 10:50Speaker 1: And it's that convergence that lets us trust statistical methods exactly.
- 10:54Speaker 2: It validates the whole idea of using probabilities and statistics
- 10:57Speaker 2: derived from experiments or samples to stand underlying truths. It
- 11:01Speaker 2: allows us to have confidence in probabilistic models.
- 11:04Speaker 1: So the LN gives us the confidence then to take
- 11:07Speaker 1: results we see in a smaller sample of data and
- 11:09Speaker 1: make reasonable conclusions about the entire population it came from,
- 11:13Speaker 1: which sounds like statistical inference.
- 11:15Speaker 2: That's precisely what statistical inference is about, and it leads
- 11:19Speaker 2: directly to the main framework we use for making those decisions.
- 11:22Speaker 2: Hypothesis testing.
- 11:23Speaker 1: Okay, hypothesis testing. This is where we formally test an
- 11:27Speaker 1: idea using the data.
- 11:28Speaker 2: Yes, it's the structured process where we use the summary
- 11:31Speaker 2: statistics we calculated combined with our understanding of probability in
- 11:35Speaker 2: the LLN to draw conclusions about a whole population based
- 11:39Speaker 2: only on evidence from a sample.
- 11:41Speaker 1: And it usually involves setting up two competing ideas beforehand.
- 11:44Speaker 2: Correct you have a kind of statistical showdown. The main
- 11:48Speaker 2: goal is to see if there's enough evidence in your
- 11:49Speaker 2: sample data to reject the null hypothesis.
- 11:52Speaker 1: The null hypothesis being the default skeptical position.
- 11:56Speaker 2: Always it's the statement of no effect, no difference, or
- 11:59Speaker 2: no relation. For example, this new drug has no effect
- 12:03Speaker 2: on recovery time compared to the place ebo. It's the
- 12:05Speaker 2: status quo assumption, and we test that against against the
- 12:08Speaker 2: alternative hypothesis. This is the statement that contradicts the null.
- 12:12Speaker 2: It's what you, as the researcher, might actually suspect or
- 12:15Speaker 2: hope to prove, like, no, this new drug does reduce
- 12:18Speaker 2: recovery time.
- 12:19Speaker 1: So the whole process is about gathering enough statistical evidence
- 12:23Speaker 1: to confidently say, Okay, we can reject the no effect
- 12:27Speaker 1: idea in favor of the there is an.
- 12:29Speaker 2: Effect idea precisely, and that level of statistical confidence, often
- 12:33Speaker 2: expressed as a P value or a confidence interval, is
- 12:37Speaker 2: what determines whether you feel justified in acting on your
- 12:39Speaker 2: findings or making a claim about the population.
- 12:42Speaker 1: All right, let's pull this together. We've walked through quite
- 12:44Speaker 1: a statistical toolkit, understanding the different types of variables you encounter.
- 12:48Speaker 2: Discrete, continuous, nominal, ordinal.
- 12:51Speaker 1: Yeah, then summarizing them with measures of center like the
- 12:54Speaker 1: mean and median, understanding spread with standard deviation especially ysds
- 13:00Speaker 1: full practically.
- 13:01Speaker 2: Right, those units matter for comparison and scaling.
- 13:03Speaker 1: Then we moved into setting up predictions by defining dependent
- 13:06Speaker 1: and independent variables, and finally, the framework for making decisions
- 13:10Speaker 1: based on sample data hypothesis testing built on the confidence
- 13:14Speaker 1: given by the law of large numbers.
- 13:16Speaker 2: It really does form the essential foundation. You can see
- 13:19Speaker 2: how these concepts are well mandatory before you jump into
- 13:22Speaker 2: the more complex mL algorithms.
- 13:24Speaker 1: They really are the entry point for any serious study
- 13:27Speaker 1: or application.
- 13:28Speaker 2: But here's a final thought, something that connects back to
- 13:30Speaker 2: that law of large numbers. The LN guarantees convergence. It
- 13:34Speaker 2: gives us certainty, but only over a massive number of trials.
- 13:39Speaker 2: A million coin flips.
- 13:40Speaker 1: Right, requires huge scale exactly.
- 13:43Speaker 2: But in the real world, doing market analysis, building a
- 13:46Speaker 2: product prototype, maybe even running a clinical trial, we almost
- 13:50Speaker 2: never have a million data points. We work with samples,
- 13:53Speaker 2: sometimes relatively small samples because collecting data is expensive or
- 13:57Speaker 2: time consuming.
- 13:58Speaker 1: So the certainty we get is an absolute. It's usually probabilistic,
- 14:02Speaker 1: like saying we're ninety five percent confident or maybe ninety
- 14:05Speaker 1: nine percent confident.
- 14:06Speaker 2: Right, which leads to the provocative question. If the law
- 14:09Speaker 2: of large numbers only guarantees truth over immense scale, how
- 14:13Speaker 2: often are our everyday decisions, maybe in business, launching a
- 14:16Speaker 2: new feature, or even interpreting a political poll, actually based
- 14:20Speaker 2: on what could be called the fallacy of small.
- 14:22Speaker 1: Numbers, meaning we're drawing conclusions from samples that might be
- 14:25Speaker 1: too small to really trust the LLNS guarantee potentially.
- 14:30Speaker 2: So the question for you, the listener, is what level
- 14:34Speaker 2: of statistical certainty that ninety five percent, that ninety nine
- 14:37Speaker 2: percent are you willing to accept, Especially when you're moving
- 14:40Speaker 2: from analyzing a potentially small, expensive sample to making a
- 14:44Speaker 2: big assumption about the entire population, an assumption that could
- 14:47Speaker 2: have major consequences, maybe cost millions.
- 14:49Speaker 1: How much uncertainty can you live with?
- 14:51Speaker 2: What's your threshold for risk framed in that statistical confidence?
- 14:54Speaker 1: Definitely something to think about. A great place to leave
- 14:57Speaker 1: it for the steep dive. Thanks for joining us,