dtreeviz  by parrt

Decision tree visualization and interpretation SDK

Created 8 years ago
3,159 stars

Top 15.0% on SourcePulse

GitHubView on GitHub
Project Summary

This Python library addresses the challenge of visualizing and interpreting decision trees, crucial components in popular machine learning models like Random Forests and gradient boosting machines. It targets machine learning engineers, researchers, and practitioners working with structured data, offering a significant aid for understanding model behavior and debugging. The primary benefit is enhanced model interpretability through detailed, educational visualizations.

How It Works

dtreeviz employs a visualization approach inspired by educational animations, utilizing an adaptor pattern (dtreeviz.model()) to extract necessary information from various decision tree implementations. This allows for a unified interface across supported libraries including scikit-learn, XGBoost, Spark MLlib, LightGBM, and TensorFlow. A key advantage is its ability to generate detailed visualizations of prediction paths, leaf node information, feature spaces, and classifier decision boundaries, offering deep insights into model logic.

Quick Start & Requirements

Installation is primarily via pip: pip install dtreeviz. Additional dependencies for specific libraries can be installed using extras, e.g., pip install dtreeviz[xgboost]. For AI chat features, install with pip install dtreeviz[ai] and set the OPENAI_API_KEY environment variable. Python version 3.6+ is required. A critical prerequisite is the Graphviz binary, with specific installation instructions provided for Mac (using Homebrew), Linux (Ubuntu: sudo apt install graphviz), and Windows (downloading MSI and updating PATH). Links to example notebooks for various supported libraries are available.

Highlighted Details

  • Supports visualization for scikit-learn, XGBoost, Spark MLlib, LightGBM, and TensorFlow decision trees.
  • The dtreeviz.decision_boundaries() function extends beyond tree models, working with any classifier supporting predict_proba().
  • Features AI-powered tree analysis, enabling ad-hoc querying of tree structure, nodes, and training data via a chat interface, with LLM-generated explanations integrated into visualizations.

Maintenance & Community

The project was initiated by Terence Parr, with significant contributions from Tudor Lapusan, Prince Grover, and Matthew Epland. Feedback and feature requests are welcomed via email or GitHub issues.

Licensing & Compatibility

The project is licensed under the permissive MIT license, allowing for broad compatibility with commercial and closed-source applications.

Limitations & Caveats

Currently, only SVG file output is supported. Jupyter Notebooks may exhibit rendering issues with SVGs due to a known bug, while Jupyter Lab displays them correctly. Platform-specific setup for the Graphviz binary can be complex. Internet Explorer is not recommended for viewing generated SVG files.

Health Check
Last Commit

9 months ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
0 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.