{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "http://dev.likejazz.com/post/183913674986/id-like-to-use-dtreeviz-but-a-svg-error-occurred" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "pycharm": { "is_executing": false, "metadata": false, "name": "#%%\n" } }, "outputs": [], "source": [ "from dtreeviz.trees import dtreeviz\n", "from sklearn.datasets import load_iris\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.tree import DecisionTreeClassifier\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "pycharm": { "is_executing": false, "metadata": false, "name": "#%%\n" } }, "outputs": [ { "data": { "text/plain": [ "0.9473684210526315" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "clf = DecisionTreeClassifier(random_state=42, max_depth=6)\n", "iris = load_iris()\n", "\n", "X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target)\n", "clf.fit(X_train, y_train)\n", "\n", "clf.score(X_test, y_test)\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "pycharm": { "is_executing": false, "metadata": false, "name": "#%%\n" } }, "outputs": [], "source": [ "viz = dtreeviz(clf, X_train, y_train, target_name='variety', \n", " feature_names=iris.feature_names,\n", " class_names=list(iris.target_names),\n", ")\n", "viz.view()\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.4" }, "stem_cell": { "cell_type": "raw", "metadata": { "pycharm": { "metadata": false } }, "source": "" } }, "nbformat": 4, "nbformat_minor": 1 }