Module 5 · Lesson 5 of 625/56 in the course~20 min
Module lessons (5/6)
Naive Bayes and text
Lesson preview5 hands-on exercises readyMachine Learning: from first principles to practice · Module 5 — Classification
Bag of words, TF-IDF and a spam classifier.
What you'll learn in this lesson
- Turn text into numbers with a bag of words and TF-IDF.
- Train a Naive Bayes spam classifier.
- Bundle vectoriser and model in one pipeline.
Overview
A model cannot read "win a free prize". We first convert each message into a vector of numbers. The simplest way is the bag of words: build a vocabulary of all words in the training messages, then represent each message by how many times each word occurs, ignoring word order.
TF-IDF refines the counts: it down-weights words that appear in almost every message (like "the") and boosts words that are distinctive.
Sections covered in this lesson
- 1The hook: models need numbers, text is words
- 2Naive Bayes
- 3Comparing text vectorisers & Naive Bayes options
- 4Try it: interactive Naive Bayes token log-odds lab
- 5Progressive examples: from raw strings to leak-free text pipelines
- 6Practice
Pro Lesson · Module 5 — Classification
Unlock "Naive Bayes and text" and the full Machine Learning: from first principles to practice curriculum
Bag of words, TF-IDF and a spam classifier.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.