An Introduction to Compression-Based Machine Learning

John Hurwitz, Edward Raff, Charles K. NicholasarXiv 2026

Here is a concise, engaging summary of the paper designed for researchers and engineers.

TL;DR

This paper formalizes the deep connection between data compression and machine learning by introducing a unified design framework ($C \rightarrow S \rightarrow M \rightarrow P$) that bridges the gap between "compression-as-similarity" and "compression-as-likelihood" paradigms. Through extensive empirical validation, the authors demonstrate that optimized compression-based ML is highly competitive with standard baselines—decisively dominating in malware detection—and that tuning these design choices can boost classification accuracy by up to 0.62 points.

What Problem Does This Paper Address?

While the theoretical link between compression and prediction is well-established (MacKay famously called them "two sides of the same coin"), practical compression-based machine learning has historically been treated as a fragmented collection of algorithmic tricks. Researchers frequently use tools like gzip as black-box classifiers without a systematic understanding of how choices like the compression algorithm, data aggregation method, or distance metrics interact.

This paper addresses the lack of a standardized framework, formalizing the design space so that compression-based ML can be systematically optimized, scaled, and compared against traditional machine learning baselines.

Methods

The authors introduce a unified four-factor design framework to characterize all compression-based ML workflows:

  1. Compression algorithm ($C$): The core engine (e.g., gzip, bzip2, LZMA, zstandard, or neural network-based compressors).
  2. Context ($S$): The side information provided to the compressor, split into the context source (e.g., a single training sample or an aggregated class dictionary) and the context injection mechanism (how it's exposed to the compressor).
  3. Compression measure ($M$): The scalar metric computed from code lengths (e.g., Normalized Compression Distance (NCD) or conditional code length).
  4. Prediction technique ($P$): The decision rule mapping the measures to a final label (e.g., $k$-Nearest Neighbors or an MDL argmin rule).
Fig. 3. The compression-based ML design space. Every method in Table I amounts to selecting one option per stage of the pipeline C →S →M →P. Compression-as-similarity (blue) picks a single-sample context, a compression distance, and a distance-based predictor; compression-as-likelihood (orange) picks a learned class model such as a compression dictionary or compressor state, a conditional code length, and the MDL rule.

The framework unifies two historically separate lenses: Compression-as-Similarity (using pairwise distances like NCD to find similar samples) and Compression-as-Likelihood (using the Minimum Description Length (MDL) principle to assign a sample to the class model that compresses it best).

Datasets

The framework was evaluated across three distinct domains to test its versatility:

  • Text: AGNews (standard topic classification).
  • Malware: Drebin (Android malware detection from raw byte sequences).
  • Images: MNIST (handwritten digit recognition).

The methods were tested across both few-shot (1, 5, and 10-shot) and full-dataset regimes.

Key Insights and Ideas

  • NCD and MDL are Mathematically Linked: The authors prove that under a uniformity condition on context complexity, NCD and MDL induce the exact same ranking over candidate classes. NCD can be interpreted as an MDL-style conditional code length where data points act as implicit models.
  • Domain-Aware Aggregation is Non-Negotiable: Standard compression-based ML relies on simple string concatenation to feed context to the compressor. While this works well for text and malware, it fails completely for images. By switching to a domain-aware aggregation method (pixel-wise addition for MNIST), the authors unlocked non-trivial image classification performance, boosting accuracy from a degenerate 0.27 to over 0.85.
  • Automatic Feature Extraction for Malware: Compression algorithms naturally excel at malware classification because dictionary-based compressors (like Lempel-Ziv variants) act as automatic, variable-length n-gram extractors, bypassing the need for complex, handcrafted feature engineering on raw binary files.

Key Results

  • Massive Tuning Gains: Moving away from the standard, unoptimized gzip + NCD baseline to the best configuration within the framework yielded massive accuracy improvements: +0.013 on Drebin, +0.170 on AG News, and a staggering +0.619 on MNIST.
  • Dominance in Few-Shot Malware Detection: In the 1-shot and 5-shot malware regimes, compression-based MDL outperformed standard feature-based baselines by 0.215 and 0.266 points, respectively.
  • Algorithmic Efficiency: MDL-based classification approaches drastically reduce computational overhead, requiring only $O(n|\mathcal{Y}|)$ compressor calls compared to the expensive $O(n^2)$ required by pairwise NCD methods, all while frequently delivering higher accuracy in text and malware domains.

Limitations and Future Work

  • Scalability of NCD: Pairwise NCD remains computationally prohibitive ($O(n^2)$) for large datasets, meaning alternative representations or MDL approaches must be favored at scale.
  • The Neural Compressor Paradox: Although modern Large Language Models (LLMs) and deep generative models achieve state-of-the-art compression ratios, initial experiments show they can perform unpredictably when used for NCD classification. Concatenating sequences often pushes the data out-of-distribution for the neural network, degrading its similarity-detection capabilities.
  • Future Directions: The authors point to the need for developing faster, specialized compressed representations (building on methods like LZJD) and designing better domain-specific aggregation methods to make neural compression practical for downstream ML tasks.

Summary updated

BibTeX
@misc{hurwitz2026introduction,
  author = {John Hurwitz and Edward Raff and Charles K. Nicholas},
  title = {{An Introduction to Compression-Based Machine Learning}},
  year = {2026},
  eprint = {2609.21309},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.21309},
}
Figure