Distilling Interpretable Models into Human-Readable Code

Walker Ravina, Ethan Sterling, Olexiy Oryeshko, Nathan Bell, Honglei Zhuang, Xuanhui Wang, Yonghui Wu, Alexander GrushetskyarXiv 2021

Introduction

In high-stakes domains such as finance, healthcare, and criminal justice, model interpretability is often a regulatory or ethical necessity. While Generalized Additive Models (GAMs) are inherently interpretable—relying on a sum of univariate functions—practitioners often face a persistent "accuracy-interpretability" trade-off. Sophisticated ensembles like bagged boosted decision trees are highly accurate but produce "jagged" shape functions that are difficult for humans to audit or deploy simply. Conversely, simpler models like those using few-segment linear curves are easy to read but hard to optimize directly from raw data. This research addresses this gap by decoupling the learning process from the representation process: training a complex "teacher" model first, then distilling its knowledge into a clean, human-readable format.

The Localized Distillation Framework

The core of the proposed approach is a two-step "Localized Distillation" pipeline. First, a high-accuracy teacher model, such as a GAM forest or a Neural Additive Model (NAM), is trained on the raw data. Second, each univariate function within the teacher model is distilled individually. By evaluating the teacher's shape function across the dataset, the researchers create $(x, y)$ pairs and fit a piecewise-linear (PWL) curve to these points.

Figure 1: Distillation of teacher model shape functions (blue points) into smooth, piecewise-linear student curves (orange lines) for features in the COMPAS dataset.

As shown in the figure above, the distillation process effectively smooths out the noise and "jaggedness" of the teacher model. This acts as a form of regularization by construction; by limiting a feature to a small number of linear segments (typically 3 to 5), the model naturally ignores erratic, non-interpretable behavior that might represent overfitting in the teacher.

The pwlfit Algorithm

The researchers developed the pwlfit algorithm to perform this distillation with high speed and robustness. Key technical innovations include:

  • Knot Discretization & Greedy Search: The algorithm discretizes the search space for "knots" (the points where linear segments meet) and employs a greedy heuristic to find optimal placement.
  • Linear Condensation: To handle massive datasets, a "condensation" technique reduces millions of data points into a few synthetic points. This allows the algorithm to solve a linear least squares problem in $O(\text{number of knots})$ time rather than $O(\text{number of data points})$.
  • Constraints: The algorithm supports monotonicity constraints and automatic input transformations, such as log scales, to better fit skewed data distributions.

Experimental Results and Insights

The method was evaluated on four diverse datasets: COMPAS (recidivism), FICO (credit), MSLR-WEB30K (ranking), and a private Chrome Web Store dataset.

Figure 5: Distillation results for ranking features, demonstrating the algorithm's ability to handle log-scaled inputs and complex shape functions with a limited number of segments.

Key findings from the experiments include:

  • Accuracy Parity: In almost all cases, the distilled 5-segment models matched the accuracy of the complex teacher models. On the COMPAS dataset, the distilled model even matched the performance of "black-box" interacting forests (AUC ~0.74).
  • Efficiency: pwlfit proved significantly faster and more robust than existing libraries like pwlf, consistently finding better fits with lower variance in runtime.
  • Code as the Model: The final output is literally source code (e.g., C++ or Python). This allows models to be integrated into standard software engineering workflows, enabling code reviews, version control, and manual expert intervention to ensure fairness or safety.

Conclusion and Future Work

By treating a machine learning model as traditional source code, this approach bridges the gap between high-performance ML and transparent software engineering. While the current focus is on univariate functions, the authors suggest that localized distillation could serve as a high-quality initialization for global optimization steps. Future work will explore extending this human-readable representation to higher-dimensional feature interactions.

Summary updated

BibTeX
@misc{ravina2021distilling,
  author = {Walker Ravina and Ethan Sterling and Olexiy Oryeshko and Nathan Bell and Honglei Zhuang and Xuanhui Wang and Yonghui Wu and Alexander Grushetsky},
  title = {{Distilling Interpretable Models into Human-Readable Code}},
  year = {2021},
  eprint = {2101.08393},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2101.08393},
}
Figure