Introductory Machine Learning
Every program earlier in this course followed a rule that a person wrote. Some rules nobody can write down: which customers are about to cancel, which transactions are fraudulent, which restaurants will have closed by next year. What usually does exist is a record of past cases with their outcomes, and machine learning is the idea of handing those examples to a program and letting it find the rule. The table is cut into features, what the model may look at, and a target, what it should predict. Producing predictions takes three lines of scikit-learn; the problem is everything around them. A model that is wrong raises no error. It prints a number, and the number looks fine. So the most important habit in the subject comes before any learning: put some rows aside as a test set, let nothing that is learned or chosen use them, and measure on them once, at the end. Before any model, compute the baseline — always answering with the more common class — because “70 % accurate” means little if always saying “no” scores 67 %.
A decision tree predicts by asking yes/no questions about the features, one after another, and a small one can be read and checked against common sense. Let it grow without limit and it gives nearly every training example a verdict of its own: training accuracy only rises, while accuracy on unseen rows rises, stalls, and falls, sometimes below the baseline. That widening gap is overfitting, and the depth is chosen on a validation set taken from the training rows, never on the test set. Accuracy also counts mistakes without saying which. The confusion matrix separates false alarms from misses, precision and recall put numbers on each, and which matters more is a business decision; when the interesting class is rare, accuracy alone is the wrong score. Finally, a model will use any column that helps, including one that would not exist on the day a real prediction is needed. That is leakage, and its symptom is a score too good to be true. A model finds what goes together, not what causes what, and it knows only the world it was shown.

Listen
| Speaker | Text |
|---|---|
| Alex | Usually, like when you sit down to write a Python script, you operate as the absolute dictator of that universe. You know the exact logic you want to execute, right? You’re in total control. Exactly. If you’re looking at property data and the area is less than 1 acre, you just write a hardcoded rule to label it small. You are laying down the tracks, and the program obediently drives the train exactly where you tell it to go, yeah, |
| Sam | because it is a completely deterministic process. I mean, the machine doesn’t think, right? It just follows your explicit, meticulously nested if statements. It’s clean, it’s predictable, and it’s entirely dependent on you knowing the exact relationship between your variables beforehand. |
| Alex | And that brings us to why we are here today. For those of you listening, specifically the graduate students in data science and analytics who are stepping into the machine learning module of your Python programming course, welcome. Glad to have you here. We are doing a deep dive into the conceptual foundation behind the code you’re about to write. Because, uh, as you transition into machine learning, you’re no longer laying the tracks. You are entering a landscape that completely flips the script on how you solve problems. Yeah, |
| Sam | you really stop writing the rules entirely. Instead, you provide the machine with historical examples, you know, past cases with known outcomes, and you basically ask the algorithm to reverse engineer the rule for you. It’s a massive architectural shift from explicit instruction. To pattern recognition and |
| Alex | the wild part about this shift is that the actual coding required to do it is shockingly brief. I mean, you’d think handing over the logic creation to a machine would require hundreds of lines of complex code. Oh, absolutely. But producing predictions in Python this way takes exactly 3 lines. You instantiate the model, you call.fit, and you call.predict. You might throw in. score to see how it did, but that’s |
| Sam | it. And that deceptive simplicity is totally a trap. Psychia learned has abstracted away all the heavy mathematical lifting because the syntax is so uniform and straightforward. The real challenge for an analyst is no longer the code itself. It’s everything else. Exactly. It’s everything happening outside of those three lines. It’s understanding whether the model is actually any good, what you’re comparing it against, whether it will survive contact with unseen data, and perhaps most dangerously, whether the model is simply cheating. |
| Alex | So let’s start with the environment you’ll be working in. You all know pandas and numpai. We aren’t here to teach you how to write a drop an a command or how to slice an array. You already passed that, right? You know that pandas manages your data tables and numpai handles the vectorized matrix math underneath, but we need to talk about how you use these tools now that your end goal is feeding a psych Hitler algorithm, |
| Sam | because you have to translate your messy human readable data into a purely mathematical language, right. And that translation process is strictly bipartite. Psychic learn mandates that you cleave your data set into two distinct entities before you do anything else, the X and the Y. Exactly. You have your features matrix universally denoted as a capital X. Which contains all the independent variables the model is allowed to observe. You know, like temperature, historical sales, day of the week, |
| Alex | and then the other piece, |
| Sam | yeah, then you extract your target array, lowercase y. Which is the specific outcome you are training the model to predict, |
| Alex | and the nature of that y variable really dictates your entire pipeline. Like if you are predicting a continuous number, say, forecasting exact revenue, you are in the realm of regression. But for this module, the focus is largely on classification. We’re looking at binary targets. Will the customer cancel their subscription? A 1 for yes, a 0 for no. And |
| Sam | because models only process numerical matrices, your data preparation phase in pandas. Takes on a completely |
| Alex | different |
| Sam | weight. It’s |
| Alex | not just making it look nice anymore, not at |
| Sam | all. Not at all. It’s no longer just about formatting for a clean report. It’s about not unintentionally lying to the algorithm. |
| Alex | This is where I really want to look at missing values in a standard analytics report. If a row is missing a critical value, your instinct is often just to drop the row or impute an average so your charts look clean. Sure, |
| Sam | that’s standard practice for reporting, |
| Alex | but the sources highlight a major philosophical difference in machine learning. A blank space in a data set isn’t just an absence of information. It is often a signal itself. |
| Sam | Yeah, it’s huge. Think about it. If you are analyzing loan applications and the field for secondary income is blank, the applicant likely didn’t just forget to fill it out, |
| Alex | right? They probably just don’t have a secondary income exactly. |
| Sam | If you just tell pandas to fill that NAN value with a 0 or a median number to satisfy psych Hitler’s requirement for complete matrices. You’ve completely erased a behavioral |
| Alex | signal. You essentially pave over the evidence, |
| Sam | precisely. You pave right over it. The standard practice here is to use pandas to impute a value so the math doesn’t break, but simultaneously generate a new boolean column that explicitly flags that the original value was missing. Oh, |
| Alex | so you keep both pieces of info. |
| Sam | Yes, you preserve the fact that the data was absent. That allows the model to decide if missing this is mathematically correlated with the target outcome. |
| Alex | That makes total sense. And that brings up another data prep hurdle that requires a shift in thinking, which is categorical variables, right? The categories. Let’s say you have a feature column for city region like north, south, east, west. The easiest pandas mapping is just assigning them 123, and 4. It’s numerical. Psych hit learn accepts it. The code runs. But doing that sabotages the model from the inside. It really |
| Sam | does because you are inadvertently teaching the algorithm false mathematics. Algorithms interpret numerical sequence as magnitude and distance. |
| Alex | Yeah, it’s exactly like assigning zip codes. I mean, zip code 90,000 is mathematically a much larger number than zip code 10,000, obviously, but that doesn’t mean a house in 90,000 is greater than or nine times further along some invisible axis than a house in 10,000, right? It’s just a label, exactly. If you feed Psy Hitler regions mapped as 1 through 4, it will try to find mathematical relationships between those numbers. It might assume that west, being a 4, is double the value of south, which is a 2. And |
| Sam | to prevent the algorithm from hallucinating those relationships, you use one hot encoding. You expand that single region column into 4 separate binary columns is north, is south, and so on, populated only with 1s and zeros. |
| Alex | So it’s just a bunch of yes or no questions. |
| Sam | Exactly. You isolate each category into its own independent yes or no question, completely removing any false hierarchy. |
| Alex | And obviously you drop all unique identifiers, right? Account numbers, customer names, transaction IDs. |
| Sam | Oh, absolutely. |
| Alex | If you leave those in a sufficiently complex model, we’ll realize that customer ID 8675309 is associated with a cancellation, and then we’ll just memorize that specific ID. Instead of learning the underlying behavioral patterns of a canceling customer. |
| Sam | And that concept of memorization versus learning, that is the central tension of machine learning. |
| Alex | Let’s pull on that thread. So we’ve formatted the matrix. X and Y are cleanly separated. Categorical variables are one hot encoded, missing values are flagged. We call fit. Psychki Learn runs its optimization to find the rules, right? |
| Sam | It does its thing. |
| Alex | But here is where I get stuck on the theory. If we have the compute power and the machine’s goal is to find the perfect mathematical boundaries separating the ones from the zeros, why wouldn’t it just eventually draw a microscopic boundary around every single data point? Like, how is that actually learning? Well, |
| Sam | you’ve just described the exact reason we can never train a model on our entire data set. Oh |
| Alex | really? Yeah. |
| Sam | If a model sees all the data during the 5th stage, it will do exactly what you suggested. It will just memorize the data set. This is why the most critical function in your pipeline is train test split. |
| Alex | So you basically carve off a chunk of your data, say 20%, and lock it in a vault, the test set. |
| Sam | The discipline around this test set must be absolute. You set it aside before you do any scaling or imputation. No peeing, no peaking whatsoever. You use absolutely nothing from it during your training or tuning phases, and you only run predictions on it once at the very end of your project to get your final performance metrics. |
| Alex | I do want to throw in a quick caveat from the sources here just for the students working with time series data. Oh, good point. Yeah, the standard train test split does a random shuffle, but if you are doing forecasting, predicting the future based on the past, an honest test. Set cannot be random. You cannot train an algorithm on data from December and test its ability to predict November. |
| Sam | That would make no sense, |
| Alex | right? Your split has to respect chronology. The test set must be the most recent block of time. |
| Sam | That’s a vital distinction. But to understand why the test set is so crucial in general, let’s look at how a model actually operates during training. The sources focus on the decision tree algorithm, which is highly intuitive. It acts like an incredibly fast game of 20 questions. |
| Alex | So it’s just asking yes or no over and over. Basically, |
| Sam | it looks at all your features and tests thousands of potential yes or no questions to see which one most cleanly separates the classes. It might ask, is the customer’s tenure less than 6 months and split the data. Then it branches and asks another question. |
| Alex | Hold on, I want to challenge the accepted wisdom on this for a second. The sources emphasize tuning a parameter called max depth, which explicitly limits how many questions the tree is allowed to ask, |
| Sam | right? It restricts the tree. |
| Alex | It artificially stops the tree from growing. But if Psychit Learn has the capacity to map every single variable and achieve 100% accuracy on the training data by asking like 50 questions, why are we handicapping it? |
| Sam | It seems counterintuitive, right? |
| Alex | It does. Why purposely dumb down the model? Isn’t the whole point of a machine to find the hyper-specific details that a human analyst would normally miss? |
| Sam | So think of the training data as a practice exam. If a student scores 100% on a practice exam, it might mean they understand the underlying physics perfectly. Or it might mean they just memorize the specific answers to those specific questions. When you leave a decision tree unrestricted, it will keep asking questions until it creates a barcode of tiny hyper-specific slivers. |
| Alex | So it’s not learning anything real, |
| Sam | right? It isn’t finding universal rules anymore. It is memorizing the noise, the flukes, and the bizarre anomalies of that exact data set. Just to get one or two weird rows classified correctly, |
| Alex | so an unrestricted tree doesn’t learn a general rule like new customers with declining usage churn. It learns a meaningless, overly complex rule like, uh, if the customer is new and they logged in on a Tuesday and their zip code ends in 4 and their secondary income is exactly $1200 they will churn. |
| Sam | Exactly. That happened to be true for one person in the historical data, but it has zero predictive power for the real world, so |
| Alex | it’s |
| Sam | useless, totally. That phenomenon is called overfitting. The model has mapped the training data way too closely, and the moment you take that overfitted model and show it your locked away test set, the unseen data, it just collapses. It fails the real exam. Exactly. It will score 99% accuracy on the training data, and perhaps 50% on the test data. The gap between those two numbers is the visual representation of overfitting. But |
| Alex | wait, if we can’t use the test set to check if we are overfitting, because we are only allowed to use the test set once at the very end, how do we figure out the correct max depth while we are building it? |
| Sam | Well, you perform another split, |
| Alex | another one, |
| Sam | yeah. You take your training data and carve out a validation set. You train the tree on the remaining data, and you test different depths on the validation set. |
| Alex | OK, so it’s like a practice test for the practice test. Sort of, |
| Sam | yeah. You were looking for the sweet spot where the model stops learning generalizable patterns and starts memorizing noise. Only after you finalize your max step using the validation set, do you finally unlock the true test set for your official score. |
| Alex | OK, let’s play that out. We’ve maintained perfect discipline. We used a validation set to tune the depth. We stopped the model from overfitting, and we run our final score command on the unseen test set. The terminal spits out 97.5% accuracy. Sounds pretty good. In any other graduate class, a 97.5% means you ace the final. You ship the model to production. |
| Sam | And in industry, shipping that model could be a massive failure. |
| Alex | Wait, really? Yeah, |
| Sam | because a raw accuracy score is meaningless in a vacuum. You have to ask, compared to what? What is the baseline? The |
| Alex | baseline, which is defined as the simplest possible guess, right? |
| Sam | Imagine you are tasked with predicting whether a company’s response to a consumer complaint will be filed late. Historically, only 1 in 40 complaints is actually late. |
| Alex | So if I write a script that has zero machine learning, it just prints the words on time for every single complaint that comes in regardless of the data. I will be right 39 out of 40 times. My blind, hard-coded script is 97.5% accurate. |
| Sam | And completely utterly useless to the business because it failed to catch a single late complaint. If you were a sophisticated decision tree achieves 97.5% accuracy on this data set. It hasn’t actually learned anything. It just mathematically realized that guessing the majority class over and over again yields a really high score. |
| Alex | So in the case of rare events like fraud or late complaints, looking at accuracy alone is essentially useless because a model could perfectly match the baseline on accuracy, but have a success rate of 0 at finding the actual phenomenon we care about, |
| Sam | exactly. Accuracy simply counts the total number of correct guesses. It doesn’t differentiate between the types of mistakes the model’s making. To diagnose the actual behavior of your model, you have to discard overall accuracy and look at the confusion matrix, the |
| Alex | confusion |
| Sam | matrix that forces you to look at the intersection of what the model predicted versus what actually happened. It breaks your results down into true positives, true negatives, false positives, and false negatives. And from those four quadrants we extract two metrics that are vastly more important than accuracy, recall and precision. |
| Alex | Let’s define the tension between them. |
| Sam | Recall is asking of all the real actual positive cases out there in the world, what percentage did our model successfully find? |
| Alex | OK, so it’s about minimizing your misses, |
| Sam | right? It is a measure of how well you limit your misses, which are your false negatives. |
| Alex | And precision looks at the other side of the coin. It asks, when the model raises its hand and confidently declares, I’ve found one, how often is it actually correct? Exactly. It is a measure of how well you limit your false alarms, which are your false positives. |
| Sam | And these two metrics inherently pull against each other. How so? Well, if you want a model with a 100% recall, meaning it catches every single instance of fraud, you just lower the threshold and have the model flag almost every transaction as fraudulent. Your recall is perfect. You didn’t miss any fraud. |
| Alex | But your precision goes off a cliff. You’ve generated 10,000 false alarms. You’re shutting down thousands of legitimate credit cards, and the business is furious, precisely, which brings up a critical point the sources make using the scenario of staffing a coffee cart. You’re building a classification model to predict whether tomorrow will be quiet, a 0, or busy, which is a |
| Sam | 1. This scenario perfectly illustrates that metrics are fundamentally business logic, disguised as mathematics. If your model predicts tomorrow will be quiet, but it turns out to be busy, that is a false negative. You missed the event. |
| Alex | And for a coffee cart, a false negative means you only scheduled one barista. You have a massive queue down the street. People are walking away in frustration, and you are bleeding potential revenue. |
| Sam | Definitely. Conversely, if your model predicts busy, but the day turns out to be quiet, that is a false positive, right? The cost of that mistake is paying 3 extra staff members to stand around wiping clean counters all day, which Just eats into your profit margins |
| Alex | and Psych Hi Len doesn’t know the hourly wage of a barista, and it certainly doesn’t know the profit margin on a latte. |
| Sam | No, it has no idea. |
| Alex | Deciding which of those two mistakes is worse, the lost sales or the wasted wages, is not a hyperparameter you can tune in Python. It is a strategic business decision. |
| Sam | Absolutely. |
| Alex | Your job as the analyst. is to adjust the model’s prediction thresholds to balance precision and recall in a way that minimizes the actual financial or operational pain for the business. |
| Sam | You’re translating business tolerance into mathematical thresholds. |
| Alex | OK, let’s say we’ve done all of this beautifully. We balanced precision and recall based on stakeholder needs. We locked our test set away, and when we finally run the numbers, the metrics are spectacular. We are crushing the baseline. Precision is high. Recall is high. It feels like we’ve solved the problem perfectly. |
| Sam | In my |
| Alex | experience, |
| Sam | when a model looks that flawless on the first try, you haven’t solved the problem. You are almost certainly cheating. |
| Alex | Oh man, we need to talk about data leakage. This is the absolute boogeyman of predictive modeling, and it will ruin you if you don’t understand the timeline of your data. |
| Sam | It really will. Data leakage occurs when your training data set includes a feature that contains information about the target variable, but that feature would not actually be available to you at the exact moment you need to make a real-world prediction. |
| Alex | The sources outline a perfect autopsy of this with the late complaints model. An agency trained a model to predict which companies were going to be late in responding to consumer complaints, |
| Sam | and the model performed exceptionally well, right? High precision, high recall. |
| Alex | But when the analysts inspected the decision tree to see how it was making these perfect guesses, they found it was heavily relying on a feature column called Company Response Category, |
| Sam | and one of the categorical values in that column was literally untimely response. |
| Alex | It’s reading the answer key. |
| Sam | It’s totally cheating. Think about the chronological impossibility of that feature. The agency needs this model to make a prediction on the very day the complaint arrives in the mailroom, right? But that response category column is only filled in by the database administrators weeks later after the company has already responded late. You’re training the model using data from the future. |
| Alex | It sounds like the algorithm has zero common sense. It’s completely greedy and will grab onto any column that mathematically correlates, even if it’s literally a side effect or a symptom of the outcome we’re trying to predict. It really has no idea. It doesn’t know chronology. It is entirely on the analysts to police the inputs. |
| Sam | Another fascinating example from the sources was a model built to predict restaurant closures. They fed the algorithm data on 52,000 restaurants. When they looked at the decision tree, the very first split, the most important question the model was asking was, are the opening hours listed on the website? |
| Alex | Which mathematically makes sense. A massive percentage of closed restaurants do not have their hours listed on the platform. |
| Sam | But again, the algorithm doesn’t understand causality. Did the restaurant go out of business because it forgot to list its opening hours, or did the listing platform scrub the hours from the database because the restaurant went out of business? It’s almost always the latter. It’s the hours disappear after the fact, which means that feature is completely useless for predicting future closure. |
| Alex | Exactly. If you deploy that model, it will just sit there waiting for a restaurant’s hours to disappear before it predicts they will close, which completely defeats the purpose of an early warning system. |
| Sam | The ultimate safeguard against leakage is a mandatory chronological audit of your features. For every single column in your X matrix, you must ask yourself, if I am running this model at 8:00 a.m. on a Tuesday to make a prediction, will I have this exact piece of data? In this exact format sitting in my hand at that precise moment. And if not, if there’s even a slight delay in when that data becomes available, you must drop the column. And |
| Alex | when you drop those leaking columns, your model’s performance will plummet back to reality. |
| Sam | It always does, |
| Alex | but that forces you to do actual data science. The sources noted that when the analysts fixed the complaints model by dropping the leaking column, they had to engineer a brand new feature from scratch. They use the historical training data to compute each company’s past share of late answers. |
| Sam | And that one carefully engineered feature brought their recall up to finding 30% of the late complaints with solid precision. |
| Alex | That’s real impact. |
| Sam | Yeah, it wasn’t an algorithmic trick. It was a human domain knowledge encoded into a new mathematical feature. |
| Alex | Most of the massive improvements in machine learning don’t come from tweaking a fancy hyperparameter in Psych hit Learn. They come from thoughtful feature engineering, which brings us to what you actually need to deliver in your assignments and future industry reports. You don’t just paste those three lines of Python code and call it a day. |
| Sam | Definitely not. Your report needs to be a defense of your methodology. You must explicitly state your baseline so your stakeholders understand the actual lift your model provides. You must report the results from your strictly isolated test set, breaking down precision and recall, not just overall accuracy, |
| Alex | and document the feature selection. |
| Sam | Yes, specifically highlighting what columns you excluded to prevent data leakage. |
| Alex | You are proving that your model is honest, and underlying all of this rigorous reporting is a core philosophy you have to embrace as you move forward in this course. A machine learning model is not a |
| Sam | brain. No, it’s not. |
| Alex | It possesses no judgment, no context, and no understanding of causality. It simply finds what goes together mathematically in the matrix you provide. |
| Sam | It only knows the specific limited world it was shown during the fit process. |
| Alex | And that leads to a final thought I want you to chew on as you open your IDEs today. The sources make a foundational point. A machine learning model can only predict the future as long as the future resembles the past, right, because of the training data. You are training these models on historical matrices, but what happens to your fraud detection model, your customer churn predictor, or your supply chain forecaster when the real world undergoes a massive. Unprecedented structural shift like a pandemic. Exactly, a global pandemic, a sudden economic collapse, or the overnight adoption of a disruptive technology. If your perfectly tuned algorithm only knows the patterns of the past, at what point does relying on historical analytics stop helping you predict the future and start actively preventing you from adapting to a new one? |
| Sam | It’s the ultimate limitation of the discipline. When the fundamental tracks of society shift, the machine cannot chart a new course. |
| Alex | So as you start typing, fit, predict and score, remember that you aren’t just letting a script drive the train anymore. You are navigating a much deeper, vastly more complex statistical reality. Good luck with the Python module. |
Presentation
Read
- Introductory Machine Learning (lecture notes)
- Kelleher, Mac Namee, D’Arcy Fundamentals of Machine Learning for Predictive Data Analytics, 2nd Edition, MIT Press, 2020, ISBN-13 978-0262044691. Electronic version available at the GSU Library.
Hands-on
Notebooks in 13-Intro-Machine-Learning
Homework
- Homework 12: Does It Beat Guessing? — due Wednesday, December 2, 2026