Abstract
We propose novel applications of parallel coordinates plots and Sankey diagrams to represent the hierarchies of interacting covariate effects in random forests. Each visualisation summarises the frequencies of all of the paths through all of the trees in a random forest. Visualisations of the roles of covariates in random forests include: ranked bar or dot charts depicting scalar metrics of the contributions of individual covariates to the predictive accuracy of the random forest; line graphs depicting various summaries of the effect of varying a particular covariate on the predictions from the random forest; heatmaps of metrics of the strengths of interactions between all pairs of covariates; and parallel coordinates plots for each response class depicting the distributions of the values of all covariates among the observations most representative of those predicted to belong that class. Together these visualisations facilitate substantial insights into the roles of covariates in a random forest but do not communicate the frequencies of the hierarchies of covariates effects across the random forest or the orders in which covariates occur in these hierarchies. Our visualisations address these gaps. We demonstrate our visualisations using a random forest fitted to publicly available data and provide a software implementation in the form of an R package.
Introduction
Random forests (RF) are widely utilized in machine learning due to their robust predictive performance and minimal tuning requirements. However, the ensemble nature of these models—often comprising hundreds or thousands of decision trees—renders them "black boxes." While existing metrics like Mean Decrease in Impurity (MDI) or Partial Dependence Plots (PDPs) provide insights into variable importance and marginal effects, they fail to capture the structural logic of the forest. Specifically, they do not illustrate the hierarchy of covariate interactions or the sequence in which variables are typically deployed across the ensemble. This paper proposes a "network flow" approach using Sankey diagrams and parallel coordinates plots to visualize these decision pathways.
Methodology: The Network Flow Perspective
The core innovation lies in treating the collective paths of a random forest as a directed network. The process involves three primary stages:
- Path Extraction: Every path from the root node to the terminal leaf is extracted from every tree in the forest.
- Parallel Coordinates Mapping: These paths are mapped onto a parallel coordinates plot. Each vertical axis represents a specific depth (rank) in the tree. Lines connect covariates used at sequential steps, with line intensity reflecting the frequency of that specific transition.
- Sankey Diagram Integration: To enhance interpretability, the authors utilize Sankey diagrams. Here, the width of the flows and the height of the nodes represent the proportion of paths utilizing specific covariates at given depths. This provides a literal "flow" of decision logic.
Case Study: Landsat Satellite Data
The methodology was demonstrated using the Statlog Landsat Satellite Data Set (available via the mlbench R package). The task involved classifying ground cover into six categories based on 36 spectral covariates (reflectance values from a 3x3 grid across four spectral bands). A 500-tree random forest was trained, achieving a classification accuracy of 75.7%.
Traditional importance metrics identified covariate x.18 as a top contributor to predictive performance. However, the network flow visualizations revealed a more nuanced reality: x.18 almost never appeared as a root node. Instead, it was most frequently utilized at the third level of the trees. This suggests that the predictive power of x.18 is contingent upon prior splits, highlighting its role as a high-order interaction variable rather than a primary driver.
In contrast, variables such as x.17, x.13, x.21, and x.29 were identified as the most frequent "root" splitters, serving as the primary axes upon which the forest begins its classification logic.
Discussion and Visual Comparisons
The study found that while parallel coordinates are useful for identifying individual paths, Sankey diagrams are superior for holistic visualization. The mapping of frequency to visual weight (node height and flow width) allows researchers to immediately identify the "highways" of logic within the model.
Furthermore, the visualizations highlighted a structural asymmetry in the forest. The "top" of the trees (root and second-level nodes) is often dominated by a small subset of influential covariates. As the depth increases, the distribution of variables becomes more uniform, reflecting the forest's tendency to explore diverse interactions in deeper nodes to refine predictions.
Conclusion and Software Implementation
The proposed visualizations bridge the gap between global importance metrics and local tree structures. By revealing the hierarchical frequency of covariate effects, researchers can gain deeper insights into the internal logic of their models. To facilitate the adoption of these methods, the authors have provided an R package, forestviews.
Future work will focus on reducing visual complexity for high-dimensional datasets through thresholding, developing interactive dashboards for real-time path exploration, and creating class-specific views to understand how the model's logic differs across various prediction outcomes.
Summary updated