liveBook · Manning

Linear discriminant analysis

As explained in Natural Language Processing in Action, Second Edition

Linear discriminant analysis is a classification technique that models classes with shared feature covariance and learns linear decision boundaries.

Linear discriminant analysis (LDA) is a fast supervised classifier for labeled vectors. It searches for an axis where projected classes are as separated as possible, then places a cutoff between them. For two classes, that axis often approximates the line connecting their centroids. section 4.2.1

A practical text-classification version represents comments with TF–IDF vectors. Subtracting the nontoxic centroid from the toxic centroid creates a direction; dot products with that direction become toxicity scores. Min–max scaling and a .5 cutoff turn scores into predictions. section 4.2.1

Toxic-comment classification

A scikit-learn LDA model fitted to TF–IDF features reaches approximately 0.999 training accuracy, but a 50/50 train/test split falls to 0.554 test accuracy. The confusion matrix shows 913 non-toxic comments classified as toxic and 201 toxic comments missed, making held-out evaluation essential.

Use LDA with these practical cautions:

  • Treat the model as a linear classifier: it assumes all classes share the same feature covariance matrix, which limits the learned boundaries to lines or hyperplanes. section 4.2.2
  • Consider quadratic discriminant analysis when classes require separate covariance estimates and curved decision boundaries. section 4.2.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains centroid projection, score normalization, implementation, and evaluation, but defers the underlying mathematics.
Examples
Uses toxic-comment vectors, centroid-based toxicity scores, scikit-learn training, held-out metrics, and confusion-matrix visualization.
What it assumes
Assumes labeled feature vectors and introduces the classifier through class centroids, dot products, and cutoff scores.
What you can do after
Apply LDA via scikit-learn, inspect predictions, and diagnose generalization with held-out scores and confusion matrices.
How it connects
Connects TF–IDF, centroids, vector projection, confusion matrices, quadratic discriminant analysis, and topic modeling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.