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

Institutions

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-07-24
DOI
https://doi.org/10.5281/zenodo.21531415
Primary Topic
Authorship Attribution and Profiling
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
preprint

Cosine, Jaccard, Euclidean and Manhattan Distances for Sparse Text Classification

Ayaz Ahmad
Zenodo (CERN European Organization for Nuclear Research)
Authorship Attribution and Profiling
preprint

Cosine, Jaccard, Euclidean and Manhattan Distances for Sparse Text Classification

Ayaz Ahmad
preprint en

Abstract

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.

Zenodo (CERN European Organization for Nuclear Research)
University of Engineering and Technology Peshawar (PK)
Peace, Justice and strong institutions
Authorship Attribution and Profiling
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Cosine, Jaccard, Euclidean and Manhattan Distances for Sparse Text Classification — Ayaz Ahmad · Zenodo (CERN European Organization for Nuclear Research) (2026) | TGRS Research Map | TGRS