Natural Language Processing · Intermediate level

Intermediate level · Module 4 of 8 · 12 guided hours

Naive Bayes and Text Classification

Text classification in depth: how Naive Bayes computes probabilities, smoothing, comparison with logistic regression, cross-validated tuning, imbalanced classes and spam filtering.

Learning objectives

  • Explain and calculate Multinomial Naive Bayes with smoothing
  • Compare and tune text classifiers with cross-validation
  • Handle imbalanced classes and evaluate per class

Topics

  • Bayes' rule for text
  • Laplace smoothing
  • spam filtering
  • logistic regression for text
  • GridSearchCV over pipelines
  • class imbalance and per-class metrics

Lessons

  1. Lesson 1 How Naive Bayes Classifies Text

    Learners work through Multinomial Naive Bayes by hand (priors, word likelihoods and Laplace smoothing) and check their numbers against scikit-learn.

    priorlikelihoodLaplace (add-one) smoothingindependence assumptionlog probabilities

  2. Lesson 2 Spam Filtering and Model Comparison

    Learners build a spam filter on the SMS Spam Collection, then compare Naive Bayes with logistic regression on TF-IDF features using cross-validation.

    SMS Spam CollectionLogisticRegressioncross_val_scoreGridSearchCVF1 score

  3. Lesson 3 Imbalanced Classes and Per-Class Evaluation

    Learners handle categories with few examples using class weights and resampling, and report precision, recall and F1 per class with macro averages.

    class imbalanceclass_weight='balanced'macro vs weighted averageprecision-recall trade-offdecision threshold

Practical activity

Build the project's subject classifier: compare tuned Naive Bayes and logistic regression on TF-IDF features, handle imbalance and report per-class results, including on the local sample.

Expected outcomes

  • Solid, well-evaluated text classifiers
  • Understanding of Naive Bayes from first principles

Assessment

Hand-calculation test (30%) and the classifier notebook with evaluation (70%).

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.