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
