Beginner level · Module 5 of 6 · 9 guided hours
Introduction to Text Classification
Turning text into numbers with a bag of words, training a first classifier with scikit-learn, and evaluating it with a test set, a confusion matrix and error analysis.
Learning objectives
- Represent text as word counts with CountVectorizer
- Train and test a simple classifier with scikit-learn
- Evaluate a classifier with accuracy, a confusion matrix and error analysis
Topics
- bag of words
- CountVectorizer
- train/test split
- Multinomial Naive Bayes
- accuracy and confusion matrix
- error analysis
Lessons
-
Lesson 1 Bag of Words: Turning Text into Numbers
Learners see how CountVectorizer builds a vocabulary and turns each message into a row of word counts, the simplest representation that classifiers can use.
vocabularydocument-term matrixCountVectorizersparse matrixword order lost
-
Lesson 2 Training a First Text Classifier
Learners combine CountVectorizer and Multinomial Naive Bayes in a scikit-learn pipeline, train it on labelled enquiries and classify new messages.
PipelineMultinomialNBtrain_test_splitpredictpredict_proba
-
Lesson 3 Evaluating a Classifier and Analysing Errors
Learners measure accuracy, read a confusion matrix, compute precision and recall for one category and study the misclassified messages to decide what to improve.
accuracyconfusion matrixprecisionrecallerror analysis
Practical activity
Train, evaluate and improve the level project classifier, and report accuracy, the confusion matrix, per-category recall and an error analysis.
Expected outcomes
- A working, evaluated text classifier
- Skill in error analysis
Assessment
Notebook review of the classifier and evaluation (70%) and an oral explanation of the confusion matrix (30%).
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.