Differential testing for machine learning: an analysis for classification algorithms beyond deep learning

Steffen Herbold, Steffen Tunkel

Abstract

Differential testing is a useful approach that uses different implementations of the same algorithms and compares the results for software testing. In recent years, this approach was successfully used for test campaigns of deep learning frameworks. There is little knowledge about the application of differential testing beyond deep learning. Within this article, we want to close this gap for classification algorithms. We conduct a case study using Scikit-learn, Weka, Spark MLlib, and Caret in which we identify the potential of differential testing by considering which algorithms are available in multiple frameworks, the feasibility by identifying pairs of algorithms that should exhibit the same behavior, and the effectiveness by executing tests for the identified pairs and analyzing the deviations. While we found a large potential for popular algorithms, the feasibility seems limited because, often, it is not possible to determine configurations that are the same in other frameworks. The execution of the feasible tests revealed that there is a large number of deviations for the scores and classes. Only a lenient approach based on statistical significance of classes does not lead to a huge amount of test failures. The potential of differential testing beyond deep learning seems limited for research into the quality of machine learning libraries. Practitioners may still use the approach if they have deep knowledge about implementations, especially if a coarse oracle that only considers significant differences of classes is sufficient.

Introduction: The Oracle Problem in Machine Learning

In traditional software engineering, testing relies on a clear expectation of output for a given input. Machine learning (ML) introduces the "Oracle Problem," where determining whether a model's prediction is correct—or if the underlying library contains a bug—is non-trivial. Differential testing offers a potential solution by comparing outputs from different implementations of the same algorithm. While this has proven effective for standardized deep learning architectures, its applicability to "traditional" ML algorithms like Random Forests or Support Vector Machines (SVM) remains under-explored.

Methodology

This study evaluates the potential, feasibility, and effectiveness of differential testing across four prominent ML frameworks: Scikit-learn (Python), Weka (Java), Spark MLlib (Scala), and Caret (R). The research was structured into three distinct phases:

  1. Potential Analysis: An audit of API documentation to determine the overlap of algorithm implementations across the four frameworks.
  2. Feasibility Assessment: An attempt to manually match hyperparameters (e.g., regularization strength, tree depth, kernel types) to create "identical" configurations.
  3. Effectiveness Testing: The execution of 87 matched algorithm pairs across four datasets, evaluated against four distinct test oracles:
  4. Absolute Class Equality: Exact label matching.
  5. Absolute Score Equality: Probability matching within a 0.001 tolerance.
  6. Statistical Class Significance: Chi-Squared test on class distributions.
  7. Statistical Score Significance: Kolmogorov-Smirnov test on score distributions.

Experimental Setup

The effectiveness phase utilized four binary classification datasets:

  • UNIFORM: Synthetic data with linear separation.
  • RANDOM: Synthetic noise data with random class assignments.
  • BC (Breast Cancer): A classic UCI repository dataset with 569 instances and 30 features.
  • WINE: A UCI dataset with 178 instances and 11 features.

Key Findings

The Hyperparameter Trap

The primary obstacle to differential testing is not mathematical divergence but interface inconsistency. Frameworks rarely share default settings, and many critical implementation details—such as tie-breaking rules or missing value handling—are hard-coded and not exposed as hyperparameters. This makes achieving a true 1:1 comparison between libraries nearly impossible.

High Deviation in Results

The study found that even deterministic algorithms rarely produce identical results across different libraries. Numerical optimization differences and floating-point handling lead to compounding variances. In 696 total comparisons, 65.6% of pairs exhibited at least one difference in classification. Probability scores were even noisier, with 72% of pairs showing absolute differences.

The Necessity of Lenient Oracles

Strict equality oracles (absolute class or score matching) result in an overwhelming number of false positives. The only oracle that provided a manageable failure rate was the Chi-Squared test on class distributions, where only 9.6% of differences were found to be statistically significant.

Conclusion

While there is high potential for differential testing due to the overlap of algorithm families across frameworks, its practical feasibility is limited by implementation "noise." For researchers, the high rate of natural deviation makes it a difficult tool for automated quality assurance. For practitioners, differential testing may only be viable when paired with deep implementation knowledge and the use of statistical, rather than absolute, oracles. Future research may find more success in metamorphic testing as a more robust alternative for validating traditional machine learning libraries.

Summary updated

BibTeX
@inproceedings{herbold2023differential,
  author = {Steffen Herbold and Steffen Tunkel},
  title = {{Differential testing for machine learning: an analysis for classification algorithms beyond deep learning}},
  booktitle = {Empir. Softw. Eng},
  year = {2023},
  url = {https://openreview.net/forum?id=_tNcpzINP4Z},
}
Figure