Cosine, Jaccard, Euclidean and Manhattan Distances for Sparse Text Classification
Choosing a distance measure is one of the earliest and least examined decisions in a text mining pipeline, yet it can determine whether a system works at all. This study quantifies that effect by comparing cosine, Jaccard, Euclidean and Manhattan distances on a deliberately controlled document classification task. Four categories of the 20 Newsgroups corpus — computer graphics, baseball, medicine and firearms policy — supply 2,256 posts, represented as TF-IDF vectors over a 21,951-term vocabulary and classified with a five-neighbour k-nearest neighbours rule. Only the distance measure varies; corpus, preprocessing, feature space and train/test split are held fixed, so any difference in outcome is attributable to the measure alone. Cosine distance reaches 0.900 accuracy and 0.899 macro F1-score. Jaccard distance follows at 0.808 on both, despite discarding term-frequency information entirely. The magnitude-sensitive measures collapse: Euclidean reaches 0.362 macro F1 and Manhattan 0.156, at or below the level expected from a degenerate classifier on four categories. The pattern holds across accuracy, precision and recall, and is explained by the geometry of sparse high-dimensional space, in which summed coordinate differences are dominated by document length rather than by topic. The findings argue that direction-based comparison should be the default for TF-IDF representations, that set-based comparison remains competitive for topic-level tasks, and that magnitude-based measures require explicit length normalisation before they are usable on text.
Authors
- Ayaz Ahmad (ORCID: https://orcid.org/0009-0000-8651-2485)
Institutions
- University of Engineering and Technology Peshawar (PK)
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-07-24
- DOI
- https://doi.org/10.5281/zenodo.21531416
- Primary Topic
- Authorship Attribution and Profiling
- Type
- preprint