← All courses CSIS 3352 · Module 5

Machine Learning Fundamentals and Model Evaluation

📅 Quiz 3 (10 pts) — expected in class Tue Oct 6; not in Blackboard as of the Oct 4 scan · On the Midterm (Modules 1–9) — moved to Tue Oct 27
📌 The Lecture 5 deck states no learning objectives. The 17 objectives below are derived from the lecture's closing summary — 4 groups: ML types · training & prediction · evaluation metrics · cross-validation and fitting. Each objective's bullets are also its Concept Check rubric.
📌 Metrics order: the confusion matrix comes before accuracy, precision, recall, and F1, because every metric is calculated from it.

Study Guide

Module 5 · 4 parts · grouped the way the lecture's closing summary groups them
📌 Everything here comes from the Lecture 5 deck. The diagrams are redrawn from the lecture's pictures. Purple Study aid boxes are memory tricks and links back to Module 4 — not lecture content, and not on the quiz or flashcards. The second worked metric example uses invented counts and is labeled.

What machine learning is

  • Machine learning — a field of AI where systems learn patterns from data, instead of being explicitly programmed with rules.
  • Gets better with data — "The more data and experience the system gets, the smarter and more accurate it becomes."
  • Reach — powers everything from spam filters to self-driving cars.
DataLearning (algorithms)Patterns & predictionsSmart decisions

The three types at a glance

Labeled dataYesNo= known answerNo labelsdashed outline = group foundAgent + environmentAgentWorldactionreward / penalty+10 good · −5 bad
TypeLearns fromGoalMain taskExamples
SupervisedLabeled data — every example already has a known correct answerLearn a mapping from inputs (features) to outputs (labels)Classification (categories) and regression (numbers)Spam vs. not spam; a house's price
UnsupervisedData with no labels or correct answersDiscover hidden structure, groupings, or relationshipsClustering — grouping similar items togetherCustomer segmentation; grouping similar news articles
ReinforcementInteracting with an environment — rewards or penalties for its actionsLearn a strategy (a policy) that maximizes long-term reward through trial and errorNot named as a single task in the lectureGame-playing AI; robotics; self-driving car decision-making

Supervised learning

  • Labeled data — the model learns from examples that already have a known correct answer.
  • Goal — learn a mapping from inputs (features) to outputs (labels).
  • Training — the algorithm learns the relationship between features and labels.
  • Predict / inference — the model uses what it learned to make predictions on new, unseen data.
1. Labeled data2. Train the model3. Predict / inference4. Output

A labeled dataset — the last column is the known answer:

Feature 1Feature 2…Answer (label)
2.13.4…Yes
1.52.1…No
3.21.8…Yes
2.73.1…No
1.82.9…Yes

Supervised learning's two tasks:

Classification→ a category (Spam / Not spam)Regressionprice→ a number (e.g., house price)
TaskPredictsOutputExample
ClassificationCategoriesDiscrete — Yes/No, Spam/Not Spam, Cat/DogIs this email spam or not spam?
RegressionNumbersContinuous — price, temperature, sales (e.g., 12.5, 98.7)Predicting the price of a house
🧩 Study aid — X and y. The lecture calls the inputs features and the outputs labels; its fitting charts label the axes Feature and Target. Same split you used in Module 4: uppercase X = the features, lowercase y = the target (the label column). Unsupervised data has no labels, so there's no y to learn.

Unsupervised learning

  • No labels — the model finds patterns in data that has no labels or correct answers.
  • Goal — discover hidden structure, groupings, or relationships.
  • Clustering — the main task: similar items are grouped together, forming clusters or segments.
  • Benefits — no labeled data needed; finds hidden patterns; useful for exploration and segmentation.
  • Output — meaningful groups that help you understand the data better and make decisions.
1. Unlabeled data2. Find patterns3. Group similar items4. Insights / output

Reinforcement learning

Agentdecision makerEnvironmentthe world it acts inReward / Penalty+10−5actionfeedbackstate — the current situationGoal: learn a policy (strategy) that maximizes long-term reward
TermMeaning
AgentThe learner or decision maker that chooses actions
EnvironmentThe world the agent interacts with; it responds to actions
Reward / penaltyFeedback signal for a good (reward, e.g., +10) or bad (penalty, e.g., −5) outcome
StateThe current situation, sent from the environment back to the agent
PolicyThe strategy the agent learns to maximize long-term reward

The learning process:

Try an action (explore)Receive feedbackLearn from experienceImprove policyMaximize long-term cumulative reward
  • Examples — game-playing AI (learns winning strategies by playing games and getting rewards); self-driving car (learns safe and efficient driving by maximizing rewards, e.g., reaching the destination safely); robotics (learns tasks like pick and place by receiving rewards for successful actions).
  • Key benefits — learns optimal behavior through interaction; handles sequential decision-making problems; effective in complex, dynamic environments.

Model training: how a model learns

  • Training — showing a model many examples so it can adjust itself to fit the patterns in the data.
  • Guess, check, adjust — the model makes a guess, checks how wrong it was (its error/loss), and adjusts.
  • Repeat — this repeats many times until predictions get consistently better.
1 · Data (input)many training examples2 · Model predictionits guess: 4.23 · Compare to answeractual 7.0 → loss 2.84 · Adjust modelupdate internal parameters5 · Repeatsee the data againthe training looprepeat until the error is low
StepWhat happens
1. Data (input)Many training examples are provided to the model.
2. Model predictionThe model makes a prediction (its guess).
3. Compare to correct answerCheck how wrong the prediction was (calculate error/loss). Example: prediction 4.2, actual 7.0 → error/loss = 2.8.
4. Adjust model (learn)The model updates its internal parameters to reduce future errors.
5. RepeatThe updated model sees the data again and the cycle repeats.

Over time: poor predictions / high error → improving / lower error → better / even lower error → best model / low error. Goal achieved: accurate predictions on new, unseen data.

Key benefits: learns automatically from data; improves with more practice; adapts to complex patterns.

⚠️ Not explained in the lecture: how error/loss is calculated in general (the only example is 4.2 vs. 7.0 → 2.8, which is the gap between them), and what the model's "internal parameters" are.

Prediction: using a trained model

1. New, unseen input2. Trained model3. Prediction output
  • Prediction — once trained, a model can take brand-new, unseen input and produce an output.
  • Why it matters — this is the moment a model actually becomes useful in the real world.
  • How it works — trained on lots of labeled data → learned patterns and relationships → recognizes those patterns in new input → produces the best output based on what it learned → instant prediction without needing the correct answer.
  • Example — a trained spam model instantly labels a brand-new incoming email: Not Spam.
TrainingPrediction
InputMany training examplesBrand-new, unseen input
Needs the correct answer?Yes — compares its guess to itNo — instant prediction without it
Model changes?Yes — adjusts internal parametersNot described as changing
ResultA model that keeps getting betterA predicted label or value

Real-world example: spam detection

  • Problem type — supervised classification: is this email "spam" or "not spam"?
  • Training data — thousands of emails already labeled by humans.
  • What it learns — patterns in wording, sender behavior, links, and formatting.
  • Reach — powers the spam folder in nearly every email inbox today.
1. Training data2. The model learns3. New email arrives4. Model predicts5. Sorted automatically

An inbox the model has sorted:

FromSubjectStatus
Alice JohnsonMeeting tomorrowNot Spam
Bank AlertYour account updateNot Spam
Win a FREE iPhone!Claim your prize now!!!Spam
Cheap Meds OnlineLowest prices guaranteedSpam
NewsletterWeekly updateNot Spam
Earn $$$ FastWork from home todaySpam

Real-world example: movie recommendation

  • Inputs — your viewing history, ratings, and similar users' behavior, used to predict what you'll enjoy next.
  • Technique mix — a mix of supervised and unsupervised techniques: clustering similar viewers, predicting ratings.
  • "Why these?" — you watched similar movies; people with similar taste liked these; high predicted rating for you.
  • Reach — powers Netflix, YouTube, and nearly every streaming platform's homepage.
1. Your data2. Find similar users (clustering)3. Predict ratings4. Rank & recommend5. You enjoy!
⚠️ The lecture doesn't say which technique is which. Clustering is unsupervised learning's main task, so "clustering similar viewers" is the unsupervised part. The lecture never labels "predicting ratings" as supervised — that pairing is implied by the word "mix", not stated.

Why model evaluation matters

  • Not the finish line — building a model isn't the finish line; you have to know if it's actually good.
  • The trap — a model can look "smart" on training data but fail badly on new, real-world data.
  • What evaluation gives — honest, measurable answers about model performance.

The confusion matrix (learn this first)

The lecture covers the matrix after the metrics, but every metric is calculated directly from this table — so start here.

Predicted:PositivePredicted:NegativeActual:PositiveActual:NegativeTPTrue PositiveFNFalse NegativeFPFalse PositiveTNTrue Negative
  • True Positive — correctly predicted positive.
  • True Negative — correctly predicted negative.
  • False Positive — wrongly predicted positive.
  • False Negative — wrongly predicted negative.
🧩 Study aid — reading the names. The second word is what the model predicted (Positive / Negative). The first word says whether that prediction was right (True) or wrong (False). So a False Negative = predicted negative, and that was wrong → it was actually positive. Green cells = right, red cells = wrong.

The four metrics

MetricFormulaQuestion it answersHigh value meansMatters most whenExample
Accuracy(TP + TN) / (TP + TN + FP + FN)What percentage of predictions were completely correct?—Simple and intuitive — but can mislead on imbalanced dataAlways predicting "not spam" is 95% accurate if only 5% of emails are spam
PrecisionTP / (TP + FP)Of everything predicted positive, how many were actually correct?Very few false alarmsFalse positives are costlyWrongly flagging a real email as spam
RecallTP / (TP + FN)Of everything actually positive, how many did the model catch?Very few missed casesFalse negatives are costlyMissing a genuinely fraudulent transaction
F1 score2 × (P × R) / (P + R)The harmonic mean of precision and recall — balances both into one number—You care about both false positives and false negatives; especially on imbalanced datasets—

Which cells each metric divides by:

Predicted:PositivePredicted:NegativeActual:PositiveActual:NegativeTPTrue PositiveFNFalse NegativeFPFalse PositiveTNTrue NegativePrecision: TP ÷ (TP + FP)Predicted:PositivePredicted:NegativeActual:PositiveActual:NegativeTPTrue PositiveFNFalse NegativeFPFalse PositiveTNTrue NegativeRecall: TP ÷ (TP + FN)
🧩 Study aid — column vs. row. Precision uses the Predicted: Positive column (TP + FP). Recall uses the Actual: Positive row (TP + FN). Accuracy uses all four cells.
⚠️ Not explained in the lecture: what a "harmonic mean" is beyond the F1 formula itself, and a definition of "imbalanced data" (it's shown only through the 5%-spam example).

Worked example A — the accuracy trap

100 emailsNot spam: 95Spam: 5Model always predicts “Not spam”:accuracy = 95 / 100 = 95% — looks greatspam caught = 0 of 5 — recall = 0

The lecture gives percentages only (5% spam, 95% accurate). Using 100 emails so the counts are whole numbers:

Predicted:SpamPredicted:Not spamActual:SpamActual:Not spamTP= 0FN= 5FP= 0TN= 95
  • Accuracy — (0 + 95) / 100 = 95%. Looks great.
  • Recall — 0 / (0 + 5) = 0. It catches none of the spam. This is why accuracy can mislead on imbalanced data.
⚠️ Precision here would be 0 / (0 + 0), which can't be computed because the model never predicts positive. The lecture doesn't cover this case.

Worked example B — practice numbers (invented)

📌 These counts are made up for practice. Only the formulas come from the lecture.
Predicted:PositivePredicted:NegativeActual:PositiveActual:NegativeTP= 40FN= 20FP= 10TN= 130
  • Accuracy — (40 + 130) / 200 = 170 / 200 = 0.85 (85%)
  • Precision — 40 / (40 + 10) = 40 / 50 = 0.80
  • Recall — 40 / (40 + 20) = 40 / 60 ≈ 0.67
  • F1 — 2 × (0.80 × 0.667) / (0.80 + 0.667) ≈ 1.067 / 1.467 ≈ 0.73

Cross-validation

  • Purpose — testing a model's performance more reliably than a single train/test split.
  • k-fold cross-validation — split the data into k parts, train on k−1 parts, test on the remaining part, and repeat k times.
  • Final estimate — average the performance from all rounds.
  • Why it matters — reduces the chance of overfitting to a particular split and gives a more stable, trustworthy estimate of performance on new, unseen data.

How it works with k = 5 — each round, a different fold (orange) is the test set:

Fold 1Fold 2Fold 3Fold 4Fold 5Round 1TestTrainTrainTrainTrainScore 1Round 2TrainTestTrainTrainTrainScore 2Round 3TrainTrainTestTrainTrainScore 3Round 4TrainTrainTrainTestTrainScore 4Round 5TrainTrainTrainTrainTestScore 5Average the 5 scores → final performance estimate
🧩 Study aid — link to Module 4. Module 4's train_test_split made one split (8 train / 2 test rows). k-fold repeats the split k times so every row gets a turn in the test set.

Overfitting vs. underfitting

The same training points, fit three ways:

FeatureTargetUnderfitting — too simpleFeatureTargetGood fit — generalizesFeatureTargetOverfitting — too complex
OverfittingUnderfitting
What happensMemorizes the training data too closely, including its noise and randomnessToo simple to capture the real pattern in the data
Training dataPerforms greatPerforms poorly
New, unseen dataPerforms poorlyPerforms poorly
Common causesToo complex a model, or too little training dataToo simple a model, not enough training, or not enough relevant features
On a chartA curve that fits every bump and noise pointA straight line through curved data — misses important structure
Key takeawayLearns the noise instead of the signal; the goal is to generalize well to new, unseen dataHigh error on both training and new data
What to doNo fixes listed in the lectureUse a more complex model; train longer; add more relevant features; reduce overly strong regularization

Why avoiding overfitting matters: it leads to models that make better predictions in the real world and are more reliable and trustworthy.

⚠️ Not explained in the lecture: "regularization" (named as an underfitting fix but never defined), and "noise" / "signal" beyond "noise and randomness". No fixes for overfitting are listed — the only related tool is cross-validation, which reduces the chance of overfitting to a particular split.

Flashcards

Question
Answer

Practice Quiz

📌 Questions tagged Practice calc use made-up counts so you can drill the formulas. Fill-in-the-blank answers must match exactly (case doesn't matter).

Concept Check

Explain each objective in your own words, then self-grade against the rubric

Notes Template

Module 5 · Print this tab for handwritten recall practice

📚 Reference documentation (official — for lookup, not page content)

Supervised vs unsupervised vs RL

Classification vs regression

RL loop: agent → … → state

Training loop — 5 steps

Draw the confusion matrix

4 formulas: Acc · P · R · F1

Precision vs recall — when?

k-fold with k = 5

Overfitting vs underfitting

Spam & movie examples — type?