[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"tool-parrt--dtreeviz":3,"similar-parrt--dtreeviz":204},{"id":4,"github_repo":5,"name":6,"description_en":7,"description_zh":8,"ai_summary_zh":8,"readme_en":9,"readme_zh":10,"quickstart_zh":11,"use_case_zh":12,"hero_image_url":13,"owner_login":14,"owner_name":15,"owner_avatar_url":16,"owner_bio":17,"owner_company":18,"owner_location":19,"owner_email":20,"owner_twitter":21,"owner_website":22,"owner_url":23,"languages":24,"stars":37,"forks":38,"last_commit_at":39,"license":40,"difficulty_score":41,"env_os":42,"env_gpu":43,"env_ram":43,"env_deps":44,"category_tags":55,"github_topics":59,"view_count":68,"oss_zip_url":18,"oss_zip_packed_at":18,"status":69,"created_at":70,"updated_at":71,"faqs":72,"releases":103},3630,"parrt\u002Fdtreeviz","dtreeviz","A python library for decision tree visualization and model interpretation.","dtreeviz 是一款专为 Python 设计的决策树可视化与模型解释库。作为梯度提升机和随机森林等主流机器学习模型的核心组件，决策树的内部逻辑往往复杂难懂，而 dtreeviz 正是为了解决这一“黑盒”难题而生。它能将抽象的树状结构转化为直观、精美的图形，帮助用户轻松理解模型是如何基于特征进行判断和预测的。\n\n这款工具特别适合数据科学家、机器学习工程师以及高校研究人员使用。无论是用于教学演示、模型调试，还是向业务方汇报分析结果，dtreeviz 都能提供强有力的支持。其独特亮点在于不仅支持基础的树结构展示，还能深入呈现样本在树中的预测路径、叶子节点的数据分布详情，甚至通过色彩丰富的图表探索特征空间与决策边界。\n\n目前，dtreeviz 已广泛兼容 scikit-learn、XGBoost、LightGBM、Spark MLlib 及 TensorFlow 等主流框架。受 R2D3 教育动画启发，它在视觉设计上兼顾了美观性与信息密度，让枯燥的算法原理变得生动易懂，是提升模型可解释性的得力助手。","# dtreeviz : Decision Tree Visualization\n\n## Description\n\nA python library for decision tree visualization and model interpretation.  Decision trees are the fundamental building block of [gradient boosting machines](http:\u002F\u002Fexplained.ai\u002Fgradient-boosting\u002Findex.html) and [Random Forests](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRandom_forest)(tm), probably the two most popular machine learning models for structured data.  Visualizing decision trees is a tremendous aid when learning how these models work and when interpreting models. The visualizations are inspired by an educational animation by [R2D3](http:\u002F\u002Fwww.r2d3.us\u002F); [A visual introduction to machine learning](http:\u002F\u002Fwww.r2d3.us\u002Fvisual-intro-to-machine-learning-part-1\u002F). Please see [How to visualize decision trees](http:\u002F\u002Fexplained.ai\u002Fdecision-tree-viz\u002Findex.html) for deeper discussion of our decision tree visualization library and the visual design decisions we made.\n\nCurrently dtreeviz supports: [scikit-learn](https:\u002F\u002Fscikit-learn.org\u002Fstable), [XGBoost](https:\u002F\u002Fxgboost.readthedocs.io\u002Fen\u002Flatest), [Spark MLlib](https:\u002F\u002Fspark.apache.org\u002Fmllib\u002F), [LightGBM](https:\u002F\u002Flightgbm.readthedocs.io\u002Fen\u002Flatest\u002F), and [Tensorflow](https:\u002F\u002Fwww.tensorflow.org\u002Fdecision_forests).  See [Installation instructions](README.md#Installation).\n\n### Authors\n\n* [Terence Parr](https:\u002F\u002Fexplained.ai\u002F), a tech lead at Google, and until 2022 was a professor of data science \u002F computer science at Univ. of San Francisco, where he was founding director of the [University of San Francisco's MS in data science program](https:\u002F\u002Fwww.usfca.edu\u002Farts-sciences\u002Fgraduate-programs\u002Fdata-science) in 2012.\n* [Tudor Lapusan](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Ftudor-lapusan-5902593b\u002F)\n* [Prince Grover](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fgroverpr)\n\nWith major code and visualization clean up contributions done by [Matthew Epland](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fmatthew-epland) (@mepland).\n\n## Sample Visualizations\n\n### Tree visualizations\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Firis-TD-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fboston-TD-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fknowledge-TD-4-simple.svg\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### Prediction path explanations\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fbreast_cancer-TD-3-X.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fdiabetes-LR-2-X.svg\" width=\"300\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fknowledge-TD-15-X-simple.svg\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### Leaf information\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_497c9958bf2d.png\" width=\"150\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_393460d09996.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### Feature space exploration\n\n#### Regression\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fcars-univar-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_2ad7e5e55b7c.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_7992595e3363.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n#### Classification\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_740b55ce2712.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_ddbd10303cd4.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n#### Classification boundaries\n\nAs a utility function, dtreeviz provides `dtreeviz.decision_boundaries()` that illustrates one and two-dimensional feature space for classifiers, including colors that represent probabilities, decision boundaries, and misclassified entities. This method is not limited to tree models, by the way, and should work with any model that answers method `predict_proba()`. That means any model from scikit-learn should work (but we also made it work with Keras models that define `predict()`). (As it does not work with trees specifically, the function does not use adaptors obtained from `dtreeviz.model()`.) See [classifier-decision-boundaries.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb).\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_cd24a8bae7f0.png\" width=\"250\">\u003Cbr>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_ac260fbf4439.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_02b2de76c759.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\nSometimes it's helpful to see animations that change some of the hyper parameters. If you look in notebook [classifier-boundary-animations.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-boundary-animations.ipynb), you will see code that generates animations such as the following (animated png files):\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_db02cecf0714.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_f1a764b415c2.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n## Quick start\n\nSee [Installation instructions](README.md#Installation) then take a look at the specific [notebooks](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks) for the supported ML library you're using:\n\n* [sklearn-based examples](notebooks\u002Fdtreeviz_sklearn_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_sklearn_visualisations.ipynb))\n* [LightGBM-based examples](notebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb))\n* [Spark-based examples](notebooks\u002Fdtreeviz_spark_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_spark_visualisations.ipynb))\n* [TensorFlow-based examples](notebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb)) Also see blog at tensorflow.org [Visualizing TensorFlow Decision Forest Trees with dtreeviz](https:\u002F\u002Fwww.tensorflow.org\u002Fdecision_forests\u002Ftutorials\u002Fdtreeviz_colab)\n* [XGBoost-based examples](notebooks\u002Fdtreeviz_xgboost_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_xgboost_visualisations.ipynb))\n* [Classifier decision boundaries for any scikit-learn model.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb))\n* [Changing colors notebook](notebooks\u002Fcolors.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fcolors.ipynb))\n* [AI-powered tree analysis (sklearn)](notebooks\u002Fdtreeviz_sklearn_AI_visualisations.ipynb) - Interactive chat and explanations using LLMs\n\nTo interopt with these different libraries, dtreeviz uses an adaptor object, obtained from function `dtreeviz.model()`, to extract model information necessary for visualization. Given such an adaptor object, all of the dtreeviz functionality is available to you using the same programmer interface. The basic dtreeviz usage recipe is:\n\n1. Import dtreeviz and your decision tree library\n2. Acquire and load data into memory\n3. Train a classifier or regressor model using your decision tree library\n4. Obtain a dtreeviz adaptor model using\u003Cbr>`viz_model = dtreeviz.model(your_trained_model,...)`\n5. Call dtreeviz functions, such as\u003Cbr>`viz_model.view()` or `viz_model.explain_prediction_path(sample_x)`\n\n**Example**\n\nHere's a complete example Python file that displays the following tree in a popup window:\n\n\u003Cimg src=\"testing\u002Fsamples\u002Firis-TD-4.svg\" width=\"200\">\n\n```python\nfrom sklearn.datasets import load_iris\nfrom sklearn.tree import DecisionTreeClassifier\n\nimport dtreeviz\n\niris = load_iris()\nX = iris.data\ny = iris.target\n\nclf = DecisionTreeClassifier(max_depth=4)\nclf.fit(X, y)\n\nviz_model = dtreeviz.model(clf,\n                           X_train=X, y_train=y,\n                           feature_names=iris.feature_names,\n                           target_name='iris',\n                           class_names=iris.target_names)\n\nv = viz_model.view()     # render as SVG into internal object \nv.show()                 # pop up window\nv.save(\"\u002Ftmp\u002Firis.svg\")  # optionally save as svg\n```\n\nIn a notebook, you can render inline without calling `show()`. Just call `view()`:\n\n```python\nviz_model.view()       # in notebook, displays inline\n```\n\n### AI-Powered Tree Analysis\n\nWith AI integration enabled, you can ask ad hoc questions about your decision tree model using the `chat()` method. The AI has access to comprehensive knowledge about your tree structure, nodes, and training data, enabling it to answer questions about:\n\n* **Tree structure**: Overall architecture, depth, node count, splitting criteria, and tree type (classification\u002Fregression)\n* **Tree nodes**: Split conditions, feature usage, node statistics, sample distributions, and purity measures at internal nodes\n* **Leaf nodes**: Predictions, confidence scores, sample counts, and class distributions\n* **Training dataset**: Feature statistics, target distributions, and data characteristics within nodes or leaves\n\n```python\n# Enable AI chat when creating the model\nviz_model = dtreeviz.model(tree_classifier,\n                           X_train=dataset[features], y_train=dataset[target],\n                           feature_names=features,\n                           target_name=target, class_names=[\"perish\", \"survive\"],\n                           ai_chat=True,\n                           ai_model=\"gpt-4.1-mini\",\n                           max_history_messages=10)\n\n# Ask questions about your tree\nviz_model.chat(\"Please give me a short summary of the tree structure?\")\nviz_model.chat(\"Which leaf nodes have the lowest prediction confidence?\")\n```\n\nAdditionally, when `ai_chat=True` is enabled, the main visualization methods (like `view()`) will automatically include an LLM-generated explanation alongside the visual output, providing both graphical and natural language interpretations of your decision tree.\n\nRequires `pip install dtreeviz[ai]` and an OpenAI API key set as `OPENAI_API_KEY` environment variable. See the [AI-powered tree analysis notebook](notebooks\u002Fdtreeviz_sklearn_AI_visualisations.ipynb) for more examples.\n\n## Installation\n\nInstall anaconda3 on your system, if not already done.\n\nYou might verify that you do not have conda-installed graphviz-related packages installed because dtreeviz needs the pip versions; you can remove them from conda space by doing:\n\n```bash\nconda uninstall python-graphviz\nconda uninstall graphviz\n```\n\nTo install (Python >=3.6 only), do this (from Anaconda Prompt on Windows!):\n\n```bash\npip install dtreeviz             # install dtreeviz for sklearn\npip install dtreeviz[xgboost]    # install XGBoost related dependency\npip install dtreeviz[pyspark]    # install pyspark related dependency\npip install dtreeviz[lightgbm]   # install LightGBM related dependency\npip install dtreeviz[tensorflow_decision_forests]   # install tensorflow_decision_forests related dependency\npip install dtreeviz[ai]         # install AI chat\u002Fexplanation features (requires OpenAI API key)\npip install dtreeviz[all]        # install all related dependencies\n```\n\nThis should also pull in the `graphviz` Python library (>=0.9), which we are using for platform specific stuff.\n\n**Limitations.** Only svg files can be generated at this time, which reduces dependencies and dramatically simplifies install process.\n\nPlease email [Terence](mailto:parrt@antlr.org) with any helpful notes on making dtreeviz work (better) on other platforms. Thanks! \n\nFor your specific platform, please see the following subsections.\n\n### Mac\n\nMake sure to have the latest XCode installed and command-line tools installed. You can run `xcode-select --install` from the command-line to install those if XCode is already installed. You also have to sign the XCode license agreement, which you can do with `sudo xcodebuild -license` from command-line. The brew install shown next needs to build graphviz, so you need XCode set up properly.\n\nYou need the graphviz binary for `dot`. Make sure you have latest version (verified on 10.13, 10.14):\n\n```bash\nbrew reinstall graphviz\n```\n\nJust to be sure, remove `dot` from any anaconda installation, for example:\n\n```bash\nrm ~\u002Fanaconda3\u002Fbin\u002Fdot\n```\n\nFrom command line, this command\n\n```bash\ndot -Tsvg\n```\n\nshould work, in the sense that it just stares at you without giving an error. You can hit control-C to escape back to the shell.  Make sure that you are using the right `dot` as installed by brew:\n\n```bash\n$ which dot\n\u002Fusr\u002Flocal\u002Fbin\u002Fdot\n$ ls -l $(which dot)\nlrwxr-xr-x  1 parrt  wheel  33 May 26 11:04 \u002Fusr\u002Flocal\u002Fbin\u002Fdot@ -> ..\u002FCellar\u002Fgraphviz\u002F2.40.1\u002Fbin\u002Fdot\n$\n```\n\n**Limitations.** Jupyter notebook has a bug where they do not show .svg files correctly, but Juypter Lab has no problem.\n\n### Linux (Ubuntu 18.04)\n\nTo get the `dot` binary do:\n \n```bash\nsudo apt install graphviz\n```\n\n**Limitations.** The `view()` method works to pop up a new window and images appear inline for jupyter notebook but not jupyter lab (It gets an error parsing the SVG XML.)  The notebook images also have a font substitution from the Arial we use and so some text overlaps. Only .svg files can be generated on this platform.\n\n### Windows 10\n\n(Make sure to `pip install graphviz`, which is common to all platforms, and make sure to do this from Anaconda Prompt on Windows!)\n\n[Download graphviz-2.38.msi](https:\u002F\u002Fgraphviz.gitlab.io\u002F_pages\u002FDownload\u002FDownload_windows.html) and update your `Path` environment variable.  Add `C:\\Program Files (x86)\\Graphviz2.38\\bin` to User path and `C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe` to System Path. It's windows so you might need a reboot after updating that environment variable.  You should see this from the Anaconda Prompt:\n\n```\n(base) C:\\Users\\Terence Parr>where dot\nC:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe\n```\n\n(Do not use `conda install -c conda-forge python-graphviz` as you get an old version of `graphviz` python library.)\n\nVerify from the Anaconda Prompt that this works (capital `-V` not lowercase `-v`):\n\n```\ndot -V\n```\n\nIf it doesn't work, you have a `Path` problem. I found the following test programs useful. The first one sees if Python can find `dot`:\n\n```python\nimport os\nimport subprocess\nproc = subprocess.Popen(['dot','-V'])\nprint( os.getenv('Path') )\n```\n\nThe following version does the same thing except uses `graphviz` Python libraries backend support utilities, which is what we use in dtreeviz:\n\n```python\nimport graphviz.backend as be\ncmd = [\"dot\", \"-V\"]\nstdout, stderr = be.run(cmd, capture_output=True, check=True, quiet=False)\nprint( stderr )\n```\n\nIf you are having issues with run command you can try copying the following files from: https:\u002F\u002Fgithub.com\u002Fxflr6\u002Fgraphviz\u002Ftree\u002Fmaster\u002Fgraphviz.\n\nPlace them in the AppData\\Local\\Continuum\\anaconda3\\Lib\\site-packages\\graphviz folder.  \n\nClean out the __pycache__ directory too.\n\nFor graphviz windows install 8.0.5 and python interface v0.18+ :  \n```python\nimport graphviz.backend as be\ncmd = [\"dot\", \"-V\"]\nstdout = be.execute.run_check(cmd, capture_output=True, check=True, quiet=False)\nprint( stdout )\n```\n\nJupyter Lab and Jupyter notebook both show the inline .svg images well.\n\n### Verify graphviz installation\n\nTry making text file `t.dot` with content `digraph T { A -> B }` (paste that into a text editor, for example) and then running this from the command line:\n\n```\ndot -Tsvg -o t.svg t.dot\n```\n\nThat should give a simple `t.svg` file that opens properly.  If you get errors from `dot`, it will not work from the dtreeviz python code.  If it can't find `dot` then you didn't update your `PATH` environment variable or there is some other install issue with `graphviz`.\n\n### Limitations\n\nFinally, don't use IE to view .svg files. Use Edge as they look much better. I suspect that IE is displaying them as a rasterized not vector images. Only .svg files can be generated on this platform.\n\n## Install dtreeviz locally\n\nMake sure to follow the install guidelines above.\n\nIn order to run tests, you need to install the library with the `[dev]` extra:\n```bash \npip install dtreeviz[dev]        # Install develop dependencies\n```\n\nTo push the `dtreeviz` library to your local egg cache (force updates) during development, do this (from anaconda prompt on Windows):\n \n```bash \npython setup.py install -f\n```\n\nE.g., on Terence's box, it adds `\u002FUsers\u002Fparrt\u002Fanaconda3\u002Flib\u002Fpython3.6\u002Fsite-packages\u002Fdtreeviz-2.3.2-py3.6.egg`.\n\n## Feedback\n\nWe welcome info from users on how they use dtreeviz, what features they'd like, etc... via [email (to parrt)](mailto:parrt@antlr.org) or via an [issue](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues).\n\n## Useful Resources\n\n* [How to visualize decision trees](http:\u002F\u002Fexplained.ai\u002Fdecision-tree-viz\u002Findex.html)\n* [How to explain gradient boosting](http:\u002F\u002Fexplained.ai\u002Fgradient-boosting\u002Findex.html)\n* [The Mechanics of Machine Learning](https:\u002F\u002Fmlbook.explained.ai\u002F)\n* [Animation by R2D3](http:\u002F\u002Fwww.r2d3.us\u002F)\n* [A visual introductionn to machine learning](http:\u002F\u002Fwww.r2d3.us\u002Fvisual-intro-to-machine-learning-part-1\u002F)\n* [fast.ai's Introduction to Machine Learning for Coders MOOC](https:\u002F\u002Fcourse18.fast.ai\u002Fml.html)\n* Stef van den Elzen's [Interactive Construction, Analysis and\nVisualization of Decision Trees](http:\u002F\u002Falexandria.tue.nl\u002Fextra1\u002Fafstversl\u002Fwsk-i\u002Felzen2011.pdf)\n* Some similar feature-space visualizations in [Towards an effective cooperation of the user and the computer for classification, SIGKDD 2000](https:\u002F\u002Fgithub.com\u002FEE2dev\u002Fpublications\u002Fblob\u002Fmaster\u002FcooperativeClassification.pdf)\n* [Beautiful Decisions: Inside BigML’s Decision Trees](https:\u002F\u002Fblog.bigml.com\u002F2012\u002F01\u002F23\u002Fbeautiful-decisions-inside-bigmls-decision-trees\u002F)\n* \"SunBurst\" approach to tree visualization: [An evaluation of space-filling information visualizations\nfor depicting hierarchical structures](https:\u002F\u002Fwww.cc.gatech.edu\u002F~john.stasko\u002Fpapers\u002Fijhcs00.pdf)\n\n## License\n\nThis project is licensed under the terms of the MIT license, see [LICENSE](LICENSE).\n\n","# dtreeviz：决策树可视化\n\n## 简介\n\n一个用于决策树可视化和模型解释的 Python 库。决策树是 [梯度提升机](http:\u002F\u002Fexplained.ai\u002Fgradient-boosting\u002Findex.html) 和 [随机森林](https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRandom_forest)(tm) 的基础构建模块，它们可能是处理结构化数据时最流行的两种机器学习模型。在学习这些模型的工作原理以及解释模型时，决策树的可视化可以提供极大的帮助。这些可视化灵感来源于 [R2D3](http:\u002F\u002Fwww.r2d3.us\u002F) 制作的一段教育动画——[机器学习的视觉入门](http:\u002F\u002Fwww.r2d3.us\u002Fvisual-intro-to-machine-learning-part-1\u002F)。有关我们决策树可视化库及其视觉设计决策的更深入讨论，请参阅 [如何可视化决策树](http:\u002F\u002Fexplained.ai\u002Fdecision-tree-viz\u002Findex.html)。\n\n目前，dtreeviz 支持：[scikit-learn](https:\u002F\u002Fscikit-learn.org\u002Fstable)、[XGBoost](https:\u002F\u002Fxgboost.readthedocs.io\u002Fen\u002Flatest)、[Spark MLlib](https:\u002F\u002Fspark.apache.org\u002Fmllib\u002F)、[LightGBM](https:\u002F\u002Flightgbm.readthedocs.io\u002Fen\u002Flatest\u002F) 和 [TensorFlow](https:\u002F\u002Fwww.tensorflow.org\u002Fdecision_forests)。安装说明请参见 [README.md#Installation](README.md#Installation)。\n\n### 作者\n\n* [Terence Parr](https:\u002F\u002Fexplained.ai\u002F)，谷歌的技术负责人，2022 年之前曾任旧金山大学的数据科学\u002F计算机科学教授，并于 2012 年担任该大学 [数据科学硕士项目](https:\u002F\u002Fwww.usfca.edu\u002Farts-sciences\u002Fgraduate-programs\u002Fdata-science) 的创始主任。\n* [Tudor Lapusan](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Ftudor-lapusan-5902593b\u002F)\n* [Prince Grover](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fgroverpr)\n\n此外，[Matthew Epland](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fmatthew-epland) (@mepland) 对代码和可视化进行了大规模的优化和清理。\n\n## 示例可视化\n\n### 树形可视化\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Firis-TD-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fboston-TD-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fknowledge-TD-4-simple.svg\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### 预测路径解释\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fbreast_cancer-TD-3-X.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fdiabetes-LR-2-X.svg\" width=\"300\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fknowledge-TD-15-X-simple.svg\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### 叶节点信息\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_497c9958bf2d.png\" width=\"150\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_393460d09996.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n### 特征空间探索\n\n#### 回归\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"testing\u002Fsamples\u002Fcars-univar-2.svg\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_2ad7e5e55b7c.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_7992595e3363.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n#### 分类\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_740b55ce2712.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_ddbd10303cd4.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n#### 分类边界\n\n作为一项实用工具，dtreeviz 提供了 `dtreeviz.decision_boundaries()` 方法，用于展示分类器的一维和二维特征空间，包括表示概率的颜色、决策边界以及被错误分类的样本。值得注意的是，此方法并不局限于树模型，任何实现了 `predict_proba()` 方法的模型都可以使用。这意味着 scikit-learn 中的任何模型都适用（不过我们也使其能够与定义了 `predict()` 方法的 Keras 模型配合使用）。由于该方法不专门针对树模型，因此不会使用从 `dtreeviz.model()` 获取的适配器。更多信息请参阅 [classifier-decision-boundaries.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb)。\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_cd24a8bae7f0.png\" width=\"250\">\u003Cbr>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_ac260fbf4439.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_02b2de76c759.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n有时，查看随超参数变化的动画会很有帮助。如果您查阅笔记本 [classifier-boundary-animations.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-boundary-animations.ipynb)，您将看到生成如下动画的代码（动画 PNG 文件）：\n\n\u003Ctable cellpadding=\"0\" cellspacing=\"0\">\n\u003Ctr>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_db02cecf0714.png\" width=\"250\">\u003C\u002Ftd>\n\u003Ctd>\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_readme_f1a764b415c2.png\" width=\"250\">\u003C\u002Ftd>\n\u003C\u002Ftr>\n\u003C\u002Ftable>\n\n## 快速入门\n\n请参阅[安装说明](README.md#Installation)，然后查看您所使用的受支持机器学习库的特定[笔记本](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks)：\n\n* [基于 scikit-learn 的示例](notebooks\u002Fdtreeviz_sklearn_visualisations.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_sklearn_visualisations.ipynb)）\n* [基于 LightGBM 的示例](notebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb)）\n* [基于 Spark 的示例](notebooks\u002Fdtreeviz_spark_visualisations.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_spark_visualisations.ipynb)）\n* [基于 TensorFlow 的示例](notebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb)）。另请参阅 tensorflow.org 博客中的[使用 dtreeviz 可视化 TensorFlow 决策树森林](https:\u002F\u002Fwww.tensorflow.org\u002Fdecision_forests\u002Ftutorials\u002Fdtreeviz_colab)\n* [基于 XGBoost 的示例](notebooks\u002Fdtreeviz_xgboost_visualisations.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_xgboost_visualisations.ipynb)）\n* [适用于任何 scikit-learn 模型的分类器决策边界.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb)）\n* [更改颜色笔记本](notebooks\u002Fcolors.ipynb)（[Colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fcolors.ipynb)）\n* [AI 驱动的树分析（scikit-learn）](notebooks\u002Fdtreeviz_sklearn_AI_visualisations.ipynb)——使用 LLM 进行交互式聊天和解释\n\n为了与这些不同的库进行互操作，dtreeviz 使用一个适配器对象，该对象通过函数 `dtreeviz.model()` 获取，用于提取可视化所需的相关模型信息。有了这样的适配器对象，您就可以使用相同的编程接口访问 dtreeviz 的所有功能。基本的 dtreeviz 使用流程如下：\n\n1. 导入 dtreeviz 和您的决策树库\n2. 获取数据并将其加载到内存中\n3. 使用您的决策树库训练分类器或回归器模型\n4. 通过\u003Cbr>`viz_model = dtreeviz.model(your_trained_model,...)` 获取 dtreeviz 适配器模型\n5. 调用 dtreeviz 函数，例如\u003Cbr>`viz_model.view()` 或 `viz_model.explain_prediction_path(sample_x)`\n\n**示例**\n\n以下是一个完整的 Python 文件示例，它会在弹出窗口中显示如下树：\n\n\u003Cimg src=\"testing\u002Fsamples\u002Firis-TD-4.svg\" width=\"200\">\n\n```python\nfrom sklearn.datasets import load_iris\nfrom sklearn.tree import DecisionTreeClassifier\n\nimport dtreeviz\n\niris = load_iris()\nX = iris.data\ny = iris.target\n\nclf = DecisionTreeClassifier(max_depth=4)\nclf.fit(X, y)\n\nviz_model = dtreeviz.model(clf,\n                           X_train=X, y_train=y,\n                           feature_names=iris.feature_names,\n                           target_name='iris',\n                           class_names=iris.target_names)\n\nv = viz_model.view()     # 渲染为 SVG 到内部对象 \nv.show()                 # 弹出窗口\nv.save(\"\u002Ftmp\u002Firis.svg\")  # 可选地保存为 svg\n```\n\n在笔记本中，您可以直接内联渲染，而无需调用 `show()`。只需调用 `view()`：\n\n```python\nviz_model.view()       # 在笔记本中，直接内联显示\n```\n\n### AI 驱动的树分析\n\n启用 AI 集成后，您可以使用 `chat()` 方法临时询问有关决策树模型的问题。AI 可以访问关于您的树结构、节点和训练数据的全面知识，从而回答以下问题：\n\n* **树结构**：整体架构、深度、节点数量、分裂标准以及树的类型（分类\u002F回归）\n* **树节点**：分裂条件、特征使用情况、节点统计信息、样本分布以及内部节点的纯度指标\n* **叶节点**：预测结果、置信度分数、样本数量以及类别分布\n* **训练数据集**：特征统计信息、目标分布以及节点或叶节点内的数据特征\n\n```python\n# 创建模型时启用 AI 聊天\nviz_model = dtreeviz.model(tree_classifier,\n                           X_train=dataset[features], y_train=dataset[target],\n                           feature_names=features,\n                           target_name=target, class_names=[\"perish\", \"survive\"],\n                           ai_chat=True,\n                           ai_model=\"gpt-4.1-mini\",\n                           max_history_messages=10)\n\n# 询问关于树的问题\nviz_model.chat(\"请给我一个关于树结构的简短总结？\")\nviz_model.chat(\"哪些叶节点的预测置信度最低？\")\n```\n\n此外，当启用 `ai_chat=True` 时，主要的可视化方法（如 `view()`）会自动在视觉输出旁边包含由 LLM 生成的解释，从而为您提供决策树的图形和自然语言双重解读。\n\n需要运行 `pip install dtreeviz[ai]` 并将 OpenAI API 密钥设置为 `OPENAI_API_KEY` 环境变量。更多示例请参阅[AI 驱动的树分析笔记本](notebooks\u002Fdtreeviz_sklearn_AI_visualisations.ipynb)。\n\n## 安装\n\n如果尚未安装，请在您的系统上安装 anaconda3。\n\n您可能需要确认没有安装由 conda 提供的 graphviz 相关包，因为 dtreeviz 需要 pip 版本；您可以通过以下命令从 conda 环境中移除它们：\n\n```bash\nconda uninstall python-graphviz\nconda uninstall graphviz\n```\n\n要安装（仅限 Python >=3.6），请执行以下操作（在 Windows 上使用 Anaconda Prompt！）：\n\n```bash\npip install dtreeviz             # 安装用于 scikit-learn 的 dtreeviz\npip install dtreeviz[xgboost]    # 安装 XGBoost 相关依赖\npip install dtreeviz[pyspark]    # 安装 PySpark 相关依赖\npip install dtreeviz[lightgbm]   # 安装 LightGBM 相关依赖\npip install dtreeviz[tensorflow_decision_forests]   # 安装 TensorFlow 决策树森林相关依赖\npip install dtreeviz[ai]         # 安装 AI 聊天\u002F解释功能（需要 OpenAI API 密钥）\npip install dtreeviz[all]        # 安装所有相关依赖\n```\n\n这也将引入 `graphviz` Python 库（>=0.9），我们正利用它来处理平台特定的任务。\n\n**局限性。** 目前只能生成 SVG 文件，这减少了依赖项并大大简化了安装过程。\n\n如果您有任何关于如何让 dtreeviz 在其他平台上更好地工作的建议，请发送电子邮件至 [Terence](mailto:parrt@antlr.org)。谢谢！\n\n有关您特定平台的信息，请参阅以下小节。\n\n### Mac\n\n请确保已安装最新版本的 Xcode 和命令行工具。如果 Xcode 已经安装，可以在终端中运行 `xcode-select --install` 来安装这些工具。此外，您还需要签署 Xcode 许可协议，可以通过在终端中运行 `sudo xcodebuild -license` 来完成。接下来展示的 Homebrew 安装步骤需要编译 Graphviz，因此必须正确配置 Xcode。\n\n您需要 `dot` 可执行文件来使用 Graphviz。请确保安装的是最新版本（已在 macOS 10.13 和 10.14 上验证）：\n\n```bash\nbrew reinstall graphviz\n```\n\n为确保无误，请从任何 Anaconda 安装中移除 `dot`，例如：\n\n```bash\nrm ~\u002Fanaconda3\u002Fbin\u002Fdot\n```\n\n在终端中，以下命令应该能够正常运行：\n\n```bash\ndot -Tsvg\n```\n\n即它会静默等待输入而不报错。您可以按 Ctrl-C 返回到 shell 提示符。请确认您使用的是通过 Homebrew 安装的正确 `dot`：\n\n```bash\n$ which dot\n\u002Fusr\u002Flocal\u002Fbin\u002Fdot\n$ ls -l $(which dot)\nlrwxr-xr-x  1 parrt  wheel  33 May 26 11:04 \u002Fusr\u002Flocal\u002Fbin\u002Fdot@ -> ..\u002FCellar\u002Fgraphviz\u002F2.40.1\u002Fbin\u002Fdot\n$\n```\n\n**局限性：** Jupyter Notebook 存在一个 bug，无法正确显示 .svg 文件，但 Jupyter Lab 则没有这个问题。\n\n### Linux (Ubuntu 18.04)\n\n要获取 `dot` 可执行文件，请执行以下命令：\n\n```bash\nsudo apt install graphviz\n```\n\n**局限性：** `view()` 方法可以弹出新窗口，并且图像会在 Jupyter Notebook 中内联显示，但在 Jupyter Lab 中则会因解析 SVG XML 出错而无法正常显示。此外，Notebook 中的图像会将我们使用的 Arial 字体替换为其他字体，导致部分文本重叠。在此平台上仅能生成 .svg 文件。\n\n### Windows 10\n\n（请务必在所有平台上执行 `pip install graphviz`，并在 Windows 上通过 Anaconda Prompt 进行安装！）\n\n[下载 graphviz-2.38.msi](https:\u002F\u002Fgraphviz.gitlab.io\u002F_pages\u002FDownload\u002FDownload_windows.html)，并更新您的 `Path` 环境变量。将 `C:\\Program Files (x86)\\Graphviz2.38\\bin` 添加到用户路径，将 `C:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe` 添加到系统路径。由于是 Windows 系统，更新环境变量后可能需要重启。您应在 Anaconda Prompt 中看到如下输出：\n\n```\n(base) C:\\Users\\Terence Parr>where dot\nC:\\Program Files (x86)\\Graphviz2.38\\bin\\dot.exe\n```\n\n（请勿使用 `conda install -c conda-forge python-graphviz`，因为这会导致安装旧版本的 Graphviz Python 库。）\n\n请在 Anaconda Prompt 中验证以下命令是否生效（注意是大写的 `-V`，而非小写的 `-v`）：\n\n```\ndot -V\n```\n\n如果无效，则说明您的 `Path` 设置存在问题。我发现以下测试程序很有用。第一个程序用于检查 Python 是否能找到 `dot`：\n\n```python\nimport os\nimport subprocess\nproc = subprocess.Popen(['dot','-V'])\nprint( os.getenv('Path') )\n```\n\n第二个版本的功能相同，但使用了 Graphviz Python 库的后台支持工具，这也是 dtreeviz 中所采用的方式：\n\n```python\nimport graphviz.backend as be\ncmd = [\"dot\", \"-V\"]\nstdout, stderr = be.run(cmd, capture_output=True, check=True, quiet=False)\nprint( stderr )\n```\n\n如果您在运行命令时遇到问题，可以尝试从 [https:\u002F\u002Fgithub.com\u002Fxflr6\u002Fgraphviz\u002Ftree\u002Fmaster\u002Fgraphviz](https:\u002F\u002Fgithub.com\u002Fxflr6\u002Fgraphviz\u002Ftree\u002Fmaster\u002Fgraphviz) 复制以下文件，并将其放置在 `AppData\\Local\\Continuum\\anaconda3\\Lib\\site-packages\\graphviz` 文件夹中。同时清空 `__pycache__` 目录。\n\n对于 Graphviz Windows 版本 8.0.5 和 Python 接口 v0.18+，您可以执行以下命令：\n\n```python\nimport graphviz.backend as be\ncmd = [\"dot\", \"-V\"]\nstdout = be.execute.run_check(cmd, capture_output=True，check=True，quiet=False)\nprint( stdout )\n```\n\nJupyter Lab 和 Jupyter Notebook 都能很好地显示内联的 .svg 图像。\n\n### 验证 Graphviz 安装\n\n尝试创建一个名为 `t.dot` 的文本文件，内容为 `digraph T { A -> B }`（可以直接复制粘贴到文本编辑器中），然后在终端中运行以下命令：\n\n```bash\ndot -Tsvg -o t.svg t.dot\n```\n\n这将生成一个简单的 `t.svg` 文件，应能正常打开。如果 `dot` 报错，则 dtreeviz 的 Python 代码将无法正常工作。如果找不到 `dot`，则说明您未正确更新 `PATH` 环境变量，或 Graphviz 的安装存在其他问题。\n\n### 局限性\n\n最后，请不要使用 Internet Explorer 查看 .svg 文件，建议使用 Edge 浏览器，效果会更好。我怀疑 IE 是将 .svg 文件渲染为栅格图像而非矢量图像。在此平台上仅能生成 .svg 文件。\n\n## 在本地安装 dtreeviz\n\n请务必遵循上述安装指南。\n\n为了进行测试，您需要使用 `[dev]` 附加项安装该库：\n\n```bash\npip install dtreeviz[dev]        # 安装开发依赖\n```\n\n在开发过程中，若需将 `dtreeviz` 库强制更新到本地 egg 缓存，可在 Windows 的 Anaconda Prompt 中执行以下命令：\n\n```bash\npython setup.py install -f\n```\n\n例如，在 Terence 的机器上，这会添加 `\u002FUsers\u002Fparrt\u002Fanaconda3\u002Flib\u002Fpython3.6\u002Fsite-packages\u002Fdtreeviz-2.3.2-py3.6.egg`。\n\n## 反馈\n\n我们欢迎用户提供关于如何使用 dtreeviz、希望新增哪些功能等方面的信息，可通过 [电子邮件（parrt@antlr.org）](mailto:parrt@antlr.org) 或 [GitHub 问题页面](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues) 与我们联系。\n\n## 有用资源\n\n* [如何可视化决策树](http:\u002F\u002Fexplained.ai\u002Fdecision-tree-viz\u002Findex.html)\n* [如何解释梯度提升](http:\u002F\u002Fexplained.ai\u002Fgradient-boosting\u002Findex.html)\n* [机器学习机制](https:\u002F\u002Fmlbook.explained.ai\u002F)\n* [R2D3 的动画作品](http:\u002F\u002Fwww.r2d3.us\u002F)\n* [机器学习视觉入门](http:\u002F\u002Fwww.r2d3.us\u002Fvisual-intro-to-machine-learning-part-1\u002F)\n* [fast.ai 面向程序员的机器学习 MOOC](https:\u002F\u002Fcourse18.fast.ai\u002Fml.html)\n* Stef van den Elzen 的 [决策树的交互式构建、分析与可视化](http:\u002F\u002Falexandria.tue.nl\u002Fextra1\u002Fafstversl\u002Fwsk-i\u002Felzen2011.pdf)\n* 类似特征空间可视化的研究，见 [迈向用户与计算机在分类任务中的有效协作，SIGKDD 2000](https:\u002F\u002Fgithub.com\u002FEE2dev\u002Fpublications\u002Fblob\u002Fmaster\u002FcooperativeClassification.pdf)\n* [BigML 决策树之美](https:\u002F\u002Fblog.bigml.com\u002F2012\u002F01\u002F23\u002Fbeautiful-decisions-inside-bigmls-decision-trees\u002F)\n* “SunBurst” 树形可视化方法：[对用于展示层次结构的空间填充信息可视化技术的评估](https:\u002F\u002Fwww.cc.gatech.edu\u002F~john.stasko\u002Fpapers\u002Fijhcs00.pdf)\n\n## 许可证\n\n本项目采用 MIT 许可证授权，详情请参阅 [LICENSE](LICENSE)。","# dtreeviz 快速上手指南\n\ndtreeviz 是一个用于决策树可视化和模型解释的 Python 库。它支持 scikit-learn、XGBoost、LightGBM、Spark MLlib 和 TensorFlow Decision Forests 等主流框架，能帮助开发者直观地理解梯度提升树和随机森林等模型的工作原理。\n\n## 环境准备\n\n*   **操作系统**：Windows, macOS, Linux\n*   **Python 版本**：>= 3.6\n*   **前置依赖**：\n    *   **Graphviz 系统工具**：dtreeviz 依赖 Graphviz 进行图形渲染。请务必先在系统中安装 Graphviz 可执行文件，而不仅仅是 Python 包。\n        *   **Ubuntu\u002FDebian**: `sudo apt-get install graphviz`\n        *   **macOS (Homebrew)**: `brew install graphviz`\n        *   **Windows**: 下载并运行官方安装包 (https:\u002F\u002Fgraphviz.org\u002Fdownload\u002F)，并将安装路径添加到系统环境变量 `PATH` 中。\n    *   **注意**：如果你之前通过 `conda` 安装了 `python-graphviz` 或 `graphviz`，建议先卸载以避免冲突：\n        ```bash\n        conda uninstall python-graphviz\n        conda uninstall graphviz\n        ```\n\n## 安装步骤\n\n推荐使用 `pip` 进行安装。国内用户可添加清华源或阿里源加速下载。\n\n1.  **安装基础版（仅支持 scikit-learn）**：\n    ```bash\n    pip install dtreeviz -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n    ```\n\n2.  **安装特定框架支持**（根据需求选择）：\n    ```bash\n    # 支持 XGBoost\n    pip install dtreeviz[xgboost] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n\n    # 支持 LightGBM\n    pip install dtreeviz[lightgbm] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n\n    # 支持 PySpark\n    pip install dtreeviz[pyspark] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n\n    # 支持 TensorFlow Decision Forests\n    pip install dtreeviz[tensorflow_decision_forests] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n    ```\n\n3.  **安装所有依赖及 AI 功能**（可选）：\n    ```bash\n    # 安装所有框架支持\n    pip install dtreeviz[all] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n\n    # 安装 AI 聊天与分析功能（需配置 OPENAI_API_KEY 环境变量）\n    pip install dtreeviz[ai] -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n    ```\n\n## 基本使用\n\n以下是一个基于 `scikit-learn` 的最简使用示例，展示如何训练模型并可视化决策树。\n\n### 1. 完整脚本示例\n\n将以下代码保存为 `demo.py` 运行，将会弹出一个窗口显示决策树图像，并保存为 SVG 文件。\n\n```python\nfrom sklearn.datasets import load_iris\nfrom sklearn.tree import DecisionTreeClassifier\nimport dtreeviz\n\n# 1. 加载数据\niris = load_iris()\nX = iris.data\ny = iris.target\n\n# 2. 训练模型\nclf = DecisionTreeClassifier(max_depth=4)\nclf.fit(X, y)\n\n# 3. 创建 dtreeviz 适配器模型\nviz_model = dtreeviz.model(clf,\n                           X_train=X, y_train=y,\n                           feature_names=iris.feature_names,\n                           target_name='iris',\n                           class_names=iris.target_names)\n\n# 4. 生成视图\nv = viz_model.view()     # 渲染为 SVG 对象\nv.show()                 # 弹出窗口显示\nv.save(\"\u002Ftmp\u002Firis.svg\")  # 可选：保存为文件\n```\n\n### 2. 在 Jupyter Notebook 中使用\n\n在 Notebook 环境中，可以直接内联显示图像，无需调用 `show()`。\n\n```python\nfrom sklearn.datasets import load_iris\nfrom sklearn.tree import DecisionTreeClassifier\nimport dtreeviz\n\niris = load_iris()\nclf = DecisionTreeClassifier(max_depth=4)\nclf.fit(iris.data, iris.target)\n\nviz_model = dtreeviz.model(clf,\n                           X_train=iris.data, y_train=iris.target,\n                           feature_names=iris.feature_names,\n                           target_name='iris',\n                           class_names=iris.target_names)\n\n# 直接调用 view() 即可在单元格下方显示图像\nviz_model.view()\n```\n\n### 3. 进阶：AI 驱动的分析（可选）\n\n如果安装了 `dtreeviz[ai]` 并配置了 `OPENAI_API_KEY`，可以使用 `chat()` 方法通过自然语言询问模型结构或获取自动解释。\n\n```python\n# 创建模型时启用 ai_chat\nviz_model = dtreeviz.model(clf,\n                           X_train=X, y_train=y,\n                           feature_names=iris.feature_names,\n                           target_name='iris',\n                           class_names=iris.target_names,\n                           ai_chat=True,\n                           ai_model=\"gpt-4.1-mini\")\n\n# 询问关于树结构的问题\nviz_model.chat(\"请简要总结这棵树的结构？\")\nviz_model.chat(\"哪些叶子节点的预测置信度最低？\")\n\n# 可视化时会自动附带 LLM 生成的文字解释\nviz_model.view()\n```","某金融风控团队正在利用 XGBoost 模型评估小微企业贷款申请，急需向非技术背景的业务部门解释为何特定客户被拒绝。\n\n### 没有 dtreeviz 时\n- 只能依赖 scikit-learn 默认的文本树或简陋图形，节点重叠严重，难以看清复杂的分裂逻辑。\n- 面对“为什么拒贷”的质问，无法直观展示该样本在树中的具体决策路径，只能口头复述枯燥的规则代码。\n- 难以判断模型是否过度依赖某个单一特征（如仅看“成立年限”），缺乏对叶子节点样本分布的可视化验证手段。\n- 业务方因不信任“黑盒”模型而抵触上线，导致项目验收周期被迫延长数周。\n\n### 使用 dtreeviz 后\n- 生成色彩鲜明、布局清晰的专业决策树图，业务人员能一眼看懂从根节点到叶子的完整分类过程。\n- 利用预测路径解释功能，直接绘制出单个客户的决策轨迹，高亮显示关键分裂点，让拒贷理由有据可依。\n- 通过叶子节点信息图，直观看到该分组内历史客户的违约率分布，快速识别并修正了模型对个别特征的过拟合问题。\n- 可视化报告极大降低了沟通成本，业务部门迅速理解模型逻辑，项目顺利在一周内通过评审并投产。\n\ndtreeviz 将晦涩的算法内部机制转化为直观的视觉语言，成功架起了数据科学家与业务决策者之间的信任桥梁。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fparrt_dtreeviz_497c9958.png","parrt","Terence Parr","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fparrt_24191efb.jpg","Tech lead at Google, ex-Professor of computer\u002Fdata science, active contributor to open-source projects supporting developers. Creator of ANTLR parser generator.",null,"San Francisco","parrt@antlr.org","the_antlr_guy","http:\u002F\u002Fexplained.ai","https:\u002F\u002Fgithub.com\u002Fparrt",[25,29,33],{"name":26,"color":27,"percentage":28},"Jupyter Notebook","#DA5B0B",99.7,{"name":30,"color":31,"percentage":32},"Python","#3572A5",0.3,{"name":34,"color":35,"percentage":36},"Shell","#89e051",0,3132,340,"2026-04-04T23:03:56","MIT",1,"Linux, macOS, Windows","未说明",{"notes":45,"python":46,"dependencies":47},"1. 必须安装 Graphviz 系统工具（非仅 Python 库），若在 Conda 环境中已安装 graphviz 相关包，建议先卸载以避免冲突，改用 pip 版本。2. 支持多种机器学习框架（sklearn, XGBoost, LightGBM, Spark, TensorFlow），安装时可根据需求使用 extras 选项（如 dtreeviz[xgboost]）。3. 若需使用 AI 聊天和分析功能，需安装 dtreeviz[ai] 并设置 OPENAI_API_KEY 环境变量。4. 目前仅支持生成 SVG 格式的可视化文件。",">=3.6",[48,49,50,51,52,53,54],"graphviz>=0.9","scikit-learn","XGBoost","Spark MLlib (pyspark)","LightGBM","TensorFlow Decision Forests","openai (可选，用于 AI 聊天功能)",[56,57,58],"其他","开发框架","数据工具",[60,49,61,62,63,64,65,66,67],"machine-learning","python","data-science","xgboost","decision-trees","visualization","random-forest","model-interpretation",2,"ready","2026-03-27T02:49:30.150509","2026-04-06T05:17:41.133472",[73,78,83,88,93,98],{"id":74,"question_zh":75,"answer_zh":76,"source_url":77},16652,"在 MacOS 上安装 graphviz 时遇到 'invalid option: --with-librsvg' 错误怎么办？","该问题通常与 Homebrew 选项变更有关。解决方法是先卸载现有的 python-graphviz 和 graphviz，然后重新安装 dtreeviz，最后按照 MacOS 的说明操作。具体命令如下：\n1. conda uninstall python-graphviz\n2. conda uninstall graphviz\n3. pip install dtreeviz\n之后再次尝试安装或运行，通常在 macOS 10.13 及更高版本上可正常工作。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F33",{"id":79,"question_zh":80,"answer_zh":81,"source_url":82},16653,"遇到 'IndexError: arrays used as indices must be of integer (or boolean) type' 错误如何解决？","当树较浅或叶子节点样本不足时可能会触发此错误。一个有效的临时解决方案是在调用 dtreeviz 时设置参数 fancy=False，例如：dtreeviz(..., fancy=False)。这可以绕过导致索引类型错误的可视化渲染逻辑。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F169",{"id":84,"question_zh":85,"answer_zh":86,"source_url":87},16654,"为什么分类器的饼图显示的是训练数据（如上采样数据）的比例，而不是新数据的比例？","这是一个已知问题，之前版本的 dtreeviz 在绘制叶子节点饼图时默认使用模型训练时的数据分布。该问题已在后续版本中修复（通过 PR #282）。请确保升级到最新版本的 dtreeviz，即可正确显示用于可视化的新数据的分布比例。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F269",{"id":89,"question_zh":90,"answer_zh":91,"source_url":92},16655,"遇到 'TypeError: unhashable type: numpy.ndarray' 错误是什么原因？","此错误通常由两个原因引起：\n1. 对回归模型（Regressor）错误地调用了仅适用于分类模型的类权重计算函数。\n2. 目标变量 y（tree_y）不是简单的一维数组，而是二维数组。\n解决方法是确保传入的目标数据 y 是一维数组（1D array），如果是 DataFrame 请将其转换为 Series 或扁平化数组。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F32",{"id":94,"question_zh":95,"answer_zh":96,"source_url":97},16656,"dtreeviz 是否支持 XGBoost 和 LightGBM 模型？","是的，dtreeviz 支持通过创建提升树集成中单棵树的“影子树”（shadow tree）来可视化 XGBoost 和 LightGBM 的决策树。对于 Spark 用户，如果 XGBoost4J-Spark 的 API 与 Spark DecisionTree (mllib 版本) 相同，也可以直接使用。建议从大数据集中抽取一个小且具有代表性的样本转换为 pandas DataFrame 来进行可视化，以提高效率。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F83",{"id":99,"question_zh":100,"answer_zh":101,"source_url":102},16657,"如何在回归模型的叶子节点中查看样本目标值（y）的分布情况？","dtreeviz 支持为回归模型生成叶子节点的分裂图（split plot），以展示叶子节点样本 y 值的分布。图表左侧显示 y 轴范围，右侧紧密排列分裂图。预测条（prediction bars）已加粗显示，且叶子节点的点状分布经过优化，能清晰展示数据的方差和分布形态（类似“抖动的点线”）。只需正常调用 dtreeviz 即可自动生成此类可视化。","https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F63",[104,109,114,119,124,129,134,139,144,149,154,159,164,169,174,179,184,189,194,199],{"id":105,"version":106,"summary_zh":107,"released_at":108},98926,"2.3.1","修复 #336 ","2025-12-27T18:59:56",{"id":110,"version":111,"summary_zh":112,"released_at":113},98927,"2.3","* 为 scikit-learn 集成 AI 聊天功能\n* 修复节点\u002F叶节点不包含样本时的问题","2025-12-26T19:38:14",{"id":115,"version":116,"summary_zh":117,"released_at":118},98928,"2.2.2","请参阅 https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fmilestone\u002F40?closed=1\n\n## 贡献者\n*   2 项：[Tudor Lapusan](https:\u002F\u002Fgithub.com\u002Ftlapusan) (tlapusan)\n*   1 项：[StepanWorkV](https:\u002F\u002Fgithub.com\u002FStepanWorkV) (StepanWorkV)\n*   1 项：[Tyrion](https:\u002F\u002Fgithub.com\u002Fhxhxd) (hxhxd)\n","2023-07-13T17:20:15",{"id":120,"version":121,"summary_zh":122,"released_at":123},98929,"2.2.1","## 修复的问题\n* [TypeError: dict() 的 ** 后面的参数必须是映射类型，而不是浮点数](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F285)（兼容性）\n* [当节点只包含来自单一类别的样本时出现可视化错误（sklearn）](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F283)（缺陷）\n* [饼图显示的是分类器训练数据，而不是新数据](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F269)（功能增强）\n\n## 改进与新增功能\n* [使 sklearn 可视化支持验证数据集。](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F282)（功能增强）\n* [饼图显示的是分类器训练数据，而不是新数据](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F269)（功能增强）\n* [为 leaf_distributions 的 x 轴添加不同的显示类型。](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F254)（功能增强）\n\n## 贡献者\n*   4 项：[Tudor Lapusan](https:\u002F\u002Fgithub.com\u002Ftlapusan)（tlapusan）\n*   1 项：[Alex Moldovan](https:\u002F\u002Fgithub.com\u002FAlex-AMC)（Alex-AMC）\n*   1 项：[Rajdeep](https:\u002F\u002Fgithub.com\u002FRajdeepTarafder)（RajdeepTarafder）\n*   1 项：[HannahAlexander](https:\u002F\u002Fgithub.com\u002FHannahAlexander)\n*   1 项：[Matthew Epland](https:\u002F\u002Fgithub.com\u002Fmepland)（mepland）\n","2023-04-16T16:37:30",{"id":125,"version":126,"summary_zh":127,"released_at":128},98930,"2.2.0","在回归器和分类器中支持字符串类型的类别变量。详情请参见 https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F265 。","2023-02-20T21:24:36",{"id":130,"version":131,"summary_zh":132,"released_at":133},98931,"2.1.4","次要改进版本：https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F259","2023-02-09T18:24:07",{"id":135,"version":136,"summary_zh":137,"released_at":138},98932,"2.1.3","添加特征空间划分函数的文档。修复 tessellate() 函数中的 bug。","2023-01-29T19:27:40",{"id":140,"version":141,"summary_zh":142,"released_at":143},98933,"2.1.2","修复与 TensorFlow Trees 的兼容性问题。","2023-01-28T22:33:27",{"id":145,"version":146,"summary_zh":147,"released_at":148},98934,"2.1.1","单个功能发布：\n\n[增强的 ctree_feature_space() 函数，支持直接传入特征参数，而不再要求模型仅包含 1 或 2 个特征]（https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F253）","2023-01-22T23:33:55",{"id":150,"version":151,"summary_zh":152,"released_at":153},98935,"2.1.0","这是一个重要的清理版本，主要由 @mepland 完成大量工作；其中包含重构、错误修复以及大量的可视化优化。\n\n## 修复的问题\n* [TF 处理视图可视化中的多分类标签](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F248)（Bug）\n* [标准化大小写](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F243)（代码清理）\n* [使用 decision_boundaries 函数时出现 KeyError](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F238)（代码清理）\n* [dtreeviz_sklearn_pipeline_visualisations.ipynb 中的维度问题](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F231)（兼容性）\n* [字体名称\u002F大小未被正确应用](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F229)（Bug）\n* [sklearn 中的波士顿数据集已不再可用，影响 classifier-decision-boundaries.ipynb 和 classifier-boundary-animations.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F225)（代码清理）\n* [`ctree_leaf_distributions()` 应使用类名而非类对象](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F202)（Bug）\n* [rtreeviz_univar() 未能正确显示 X 特征](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F198)（Bug）\n* [无法更改类别名称字体](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F145)（Bug）\n* [分类器中标签过于靠近坐标轴而发生重叠](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F113)（功能改进）\n\n## 改进与新增功能\n* [对 explain_prediction_path() 进行排序](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F234)（功能改进）\n* [改进 _ctreeviz_univar()](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F227)（功能改进）\n* [修复有向图图形](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F224)（功能改进）\n* [允许图例边框为 None](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F221)（功能改进）\n* [ctree_leaf_distributions() 的 label_all_leaves 参数](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F220)（功能改进）\n* [通过 'larrow' 和 'rarrow' 参数分别设置左右箭头颜色](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F219)（功能改进）\n* [添加 matplotlib 默认颜色作为 mpl_colors](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F216)（功能改进）\n* [新增将分类器叶节点绘制成水平条形图的选项](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F215)（功能改进）\n* [分类器中标签过于靠近坐标轴而发生重叠](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F113)（功能改进）\n\n## 贡献者\n* 19 项：[Matthew Epland](https:\u002F\u002Fgithub.com\u002Fmepland) (mepland)\n* 5 项：[Terence Parr](https:\u002F\u002Fgithub.com\u002Fparrt) (parrt)\n* 2 项：[Tudor Lapusan](https:\u002F\u002Fgithub.com\u002Ftlapusan) (tlapusan)\n* 1 项：[0ptimista](https:\u002F\u002Fgithub.com\u002F0ptimista)\n* 1 项：[Tobias Windisch](https:\u002F\u002Fgithub.com\u002Fwindisch) (windisch)\n* 1 项：[HidenariUoi](https:\u002F\u002Fgithub.com\u002FHidenariUoi)","2023-01-16T21:43:04",{"id":155,"version":156,"summary_zh":157,"released_at":158},98936,"2.0.0","This release re-organizes the API to focus on using a model adaptor that adapts the visualization library to the various supported decision tree libraries.\r\n\r\nWe simplified the [README](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002FREADME.md) and rebuilt all of the library-specific notebooks to demonstrate the new API, using a common set of examples:\r\n\r\n* [sklearn-based examples](notebooks\u002Fdtreeviz_sklearn_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_sklearn_visualisations.ipynb))\r\n* [LightGBM-based examples](notebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_lightgbm_visualisations.ipynb))\r\n* [Spark-based examples](notebooks\u002Fdtreeviz_spark_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_spark_visualisations.ipynb))\r\n* [TensorFlow-based examples](notebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_tensorflow_visualisations.ipynb))\r\n* [XGBoost-based examples](notebooks\u002Fdtreeviz_xgboost_visualisations.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fdtreeviz_xgboost_visualisations.ipynb))\r\n* [Classifier decision boundaries for any scikit-learn model.ipynb](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Ftree\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fclassifier-decision-boundaries.ipynb))\r\n* [Changing colors notebook (specific to sklearn)](notebooks\u002Fcolors.ipynb) ([colab](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fparrt\u002Fdtreeviz\u002Fblob\u002Fmaster\u002Fnotebooks\u002Fcolors.ipynb))\r\n\r\n**New API**:\r\n\r\n```\r\nfrom sklearn.datasets import load_iris\r\nfrom sklearn.tree import DecisionTreeClassifier\r\nimport dtreeviz\r\n\r\niris = load_iris()\r\nX = iris.data\r\ny = iris.target\r\n\r\nclf = DecisionTreeClassifier(max_depth=4)\r\nclf.fit(X, y)\r\nviz_model = dtreeviz.model(clf,\r\n                           X_train=X, y_train=y,\r\n                           feature_names=iris.feature_names,\r\n                           target_name='iris',\r\n                           class_names=iris.target_names)\r\n\r\nv = viz_model.view() # render as SVG into internal object\r\n```\r\n\r\n**Previous API**:\r\nPreviously, we did something like this to call functions and pass in the various details of the model and training data:\r\n\r\n```\r\nfrom dtreeviz.trees import dtreeviz\r\ndtreeviz(tree_model=clf, X_train, ...)\r\n```\r\n\r\n**Using old functions with 2.0+**:\r\n\r\nFor backward compatibility to call function `dtreeviz()` and the old API, you can change the import to be:\r\n\r\n```\r\nfrom dtreeviz import *\r\ndtreeviz(tree_model=clf, X_train, ...)\r\n```\r\n\r\n**Argument name changes**:\r\n\r\nIf you were previously using internal model adaptors, such as `ShadowLightGBMTree`, please note we have changed the following argument names: `x_data`->`X_train` and `y_data`->`y_train`.\r\n\r\n**Stuff we completed**:\r\n\r\nhttps:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fmilestone\u002F30?closed=1","2022-12-27T19:58:41",{"id":160,"version":161,"summary_zh":162,"released_at":163},98937,"1.4.1","Fixing this bug: https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F196\r\n\r\n","2022-11-27T22:39:29",{"id":165,"version":166,"summary_zh":167,"released_at":168},98938,"1.4.0","Add tensorflow decision tree support.","2022-10-22T18:51:18",{"id":170,"version":171,"summary_zh":172,"released_at":173},98939,"1.3.7","Add colors to support more than 10 target classes for classification:\r\n\r\n* https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F185\r\n* ","2022-07-08T19:37:21",{"id":175,"version":176,"summary_zh":177,"released_at":178},98940,"1.3.6","This release makes a small change that really improve the speed of `dtreeviz.interpretation.explain_prediction_plain_english()`. \r\n\r\nSee [Fix: xgb_decision_tree shouldGoLeftAtSplit -- massive-speed-up #182](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpull\u002F182).","2022-04-29T17:54:45",{"id":180,"version":181,"summary_zh":182,"released_at":183},98941,"1.3.5","[Quick bug fix for scaling images](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fissues\u002F179).","2022-03-10T19:55:49",{"id":185,"version":186,"summary_zh":187,"released_at":188},98942,"1.3.4","Bug fix release: [closed PRs](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fpulls?q=is%3Apr+is%3Aclosed+milestone%3A1.3.4)","2022-03-08T17:58:51",{"id":190,"version":191,"summary_zh":192,"released_at":193},98943,"1.3.3","Minor tweaks and improvements.","2022-02-09T17:42:28",{"id":195,"version":196,"summary_zh":197,"released_at":198},98944,"1.3.2","Fix compatibility issue with 0.18 release of graphviz; fixed by 90031de435247632b75292e862e9697bb06479ca","2021-11-10T22:55:11",{"id":200,"version":201,"summary_zh":202,"released_at":203},98945,"1.3.1","Some bug fixes and [clean up](https:\u002F\u002Fgithub.com\u002Fparrt\u002Fdtreeviz\u002Fmilestone\u002F20?closed=1).","2021-09-10T20:17:53",[205,216,225,233,241,252],{"id":206,"name":207,"github_repo":208,"description_zh":209,"stars":210,"difficulty_score":211,"last_commit_at":212,"category_tags":213,"status":69},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,3,"2026-04-05T11:01:52",[57,214,215],"图像","Agent",{"id":217,"name":218,"github_repo":219,"description_zh":220,"stars":221,"difficulty_score":68,"last_commit_at":222,"category_tags":223,"status":69},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",138956,"2026-04-05T11:33:21",[57,215,224],"语言模型",{"id":226,"name":227,"github_repo":228,"description_zh":229,"stars":230,"difficulty_score":68,"last_commit_at":231,"category_tags":232,"status":69},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[57,214,215],{"id":234,"name":235,"github_repo":236,"description_zh":237,"stars":238,"difficulty_score":68,"last_commit_at":239,"category_tags":240,"status":69},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[57,224],{"id":242,"name":243,"github_repo":244,"description_zh":245,"stars":246,"difficulty_score":68,"last_commit_at":247,"category_tags":248,"status":69},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[214,58,249,250,215,56,224,57,251],"视频","插件","音频",{"id":253,"name":254,"github_repo":255,"description_zh":256,"stars":257,"difficulty_score":211,"last_commit_at":258,"category_tags":259,"status":69},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[215,214,57,224,56]]