Skip to content

Instantly share code, notes, and snippets.

@sinhrks
Last active February 22, 2018 06:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sinhrks/cc9a88f74074fc296e12 to your computer and use it in GitHub Desktop.
Save sinhrks/cc9a88f74074fc296e12 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'0.4'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
"import xgboost as xgb\n",
"from sklearn import datasets\n",
"\n",
"import matplotlib.pyplot as plt\n",
"plt.style.use('ggplot')\n",
"\n",
"xgb.__version__"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"iris = datasets.load_iris()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"650pt\" height=\"817pt\"\n",
" viewBox=\"0.00 0.00 649.71 817.24\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 813.239)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-813.239 645.706,-813.239 645.706,4 -4,4\"/>\n",
"<!-- 0 -->\n",
"<g id=\"node1\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"313.688\" cy=\"-735.937\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"313.688\" y=\"-731.737\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;2.45</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node2\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"307.213,-560.627 206.162,-560.627 206.162,-524.627 307.213,-524.627 307.213,-560.627\"/>\n",
"<text text-anchor=\"middle\" x=\"256.688\" y=\"-538.427\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.215311</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M287.757,-667.19C285.16,-659.624 282.671,-651.994 280.46,-644.634 273.044,-619.951 266.493,-591.311 262.155,-570.845\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"265.561,-570.029 260.096,-560.952 258.708,-571.456 265.561,-570.029\"/>\n",
"<text text-anchor=\"middle\" x=\"315.301\" y=\"-633.434\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node3\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"395.688\" cy=\"-542.627\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"395.688\" y=\"-538.427\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.75</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M342.252,-668.294C349.428,-651.553 357.165,-633.502 364.463,-616.474\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"367.744,-617.705 368.466,-607.135 361.31,-614.947 367.744,-617.705\"/>\n",
"<text text-anchor=\"middle\" x=\"364.688\" y=\"-633.434\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node4\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"304.688\" cy=\"-349.317\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"304.688\" y=\"-345.117\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;4.95</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M365.891,-478.985C357.681,-461.725 348.693,-442.83 340.194,-424.964\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"343.258,-423.256 335.802,-415.729 336.937,-426.263 343.258,-423.256\"/>\n",
"<text text-anchor=\"middle\" x=\"388.301\" y=\"-443.419\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node5\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"469.688\" cy=\"-349.317\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"469.688\" y=\"-345.117\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;4.85</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;4 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M420.637,-477.125C426.775,-461.256 433.41,-444.103 439.757,-427.696\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"443.111,-428.726 443.454,-418.137 436.582,-426.2 443.111,-428.726\"/>\n",
"<text text-anchor=\"middle\" x=\"441.688\" y=\"-443.419\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node6\" class=\"node\"><title>5</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"153.688\" cy=\"-156.007\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"153.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.55</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;5 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>3&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M259.587,-291.177C241.785,-268.623 221.276,-242.639 203.076,-219.58\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"205.686,-217.238 196.743,-211.557 200.191,-221.575 205.686,-217.238\"/>\n",
"<text text-anchor=\"middle\" x=\"264.301\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 6 -->\n",
"<g id=\"node7\" class=\"node\"><title>6</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"311.688\" cy=\"-156.007\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"311.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.55</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;6 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>3&#45;&gt;6</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M307.334,-275.991C307.804,-263.133 308.297,-249.677 308.774,-236.63\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"312.285,-236.395 309.153,-226.273 305.29,-236.139 312.285,-236.395\"/>\n",
"<text text-anchor=\"middle\" x=\"315.688\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 7 -->\n",
"<g id=\"node12\" class=\"node\"><title>7</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"521.601,-174.007 401.774,-174.007 401.774,-138.007 521.601,-138.007 521.601,-174.007\"/>\n",
"<text text-anchor=\"middle\" x=\"461.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;7.66345e&#45;09</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;7 -->\n",
"<g id=\"edge11\" class=\"edge\"><title>4&#45;&gt;7</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M466.663,-275.991C465.32,-243.876 463.821,-208.024 462.823,-184.151\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"466.316,-183.927 462.402,-174.082 459.322,-184.22 466.316,-183.927\"/>\n",
"<text text-anchor=\"middle\" x=\"500.301\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 8 -->\n",
"<g id=\"node13\" class=\"node\"><title>8</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"641.725,-174.007 539.65,-174.007 539.65,-138.007 641.725,-138.007 641.725,-174.007\"/>\n",
"<text text-anchor=\"middle\" x=\"590.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.213812</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;8 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>4&#45;&gt;8</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M515.428,-291.602C523.528,-280.697 531.621,-269.187 538.688,-258.015 554.069,-233.695 568.807,-204.289 578.64,-183.493\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"581.866,-184.857 582.926,-174.315 575.524,-181.895 581.866,-184.857\"/>\n",
"<text text-anchor=\"middle\" x=\"553.688\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 9 -->\n",
"<g id=\"node8\" class=\"node\"><title>9</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"97.5632,-36 -0.188225,-36 -0.188225,-0 97.5632,-0 97.5632,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"48.6875\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.428571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;9 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;9</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M111.283,-100.08C96.3954,-80.7964 80.3826,-60.055 68.2796,-44.3779\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"70.8714,-42.0076 61.99,-36.2308 65.3305,-46.2853 70.8714,-42.0076\"/>\n",
"<text text-anchor=\"middle\" x=\"120.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 10 -->\n",
"<g id=\"node9\" class=\"node\"><title>10</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"212.563,-36 114.812,-36 114.812,-0 212.563,-0 212.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"163.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;10 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5&#45;&gt;10</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M158.775,-85.8084C159.806,-71.7847 160.833,-57.8287 161.678,-46.3271\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"165.185,-46.3594 162.428,-36.1296 158.204,-45.846 165.185,-46.3594\"/>\n",
"<text text-anchor=\"middle\" x=\"168.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 11 -->\n",
"<g id=\"node10\" class=\"node\"><title>11</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"342.725,-36 240.65,-36 240.65,-0 342.725,-0 342.725,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"291.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;11 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>6&#45;&gt;11</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M301.629,-86.6053C299.514,-72.2219 297.402,-57.8623 295.673,-46.1004\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"299.12,-45.4871 294.202,-36.1028 292.195,-46.5056 299.12,-45.4871\"/>\n",
"<text text-anchor=\"middle\" x=\"334.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 12 -->\n",
"<g id=\"node11\" class=\"node\"><title>12</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"458.563,-36 360.812,-36 360.812,-0 458.563,-0 458.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"409.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;12 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>6&#45;&gt;12</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M352.397,-98.5096C365.937,-79.7185 380.347,-59.7202 391.327,-44.4806\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"394.358,-46.2621 397.364,-36.1028 388.678,-42.1699 394.358,-46.2621\"/>\n",
"<text text-anchor=\"middle\" x=\"390.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x107138b50>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dm = xgb.DMatrix(iris.data, label=iris.target,\n",
" feature_names=['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'],\n",
" feature_types=['q', 'q', 'q', 'q'])\n",
"np.random.seed(1) \n",
"params={'objective': 'multi:softprob',\n",
" 'eval_metric': 'mlogloss',\n",
" 'eta': 0.3,\n",
" 'num_class': 3}\n",
"bst = xgb.train(params, dm)\n",
"xgb.to_graphviz(bst, num_trees=1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"532pt\" height=\"661pt\"\n",
" viewBox=\"0.00 0.00 532.38 661.39\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 657.39)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-657.39 528.375,-657.39 528.375,4 -4,4\"/>\n",
"<!-- 0 -->\n",
"<g id=\"node1\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"309.188\" cy=\"-600.551\" rx=\"52.6779\" ry=\"52.6779\"/>\n",
"<text text-anchor=\"middle\" x=\"309.188\" y=\"-596.351\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node2\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"214.188\" cy=\"-442.909\" rx=\"54.6076\" ry=\"54.6076\"/>\n",
"<text text-anchor=\"middle\" x=\"214.188\" y=\"-438.709\" font-family=\"Times,serif\" font-size=\"14.00\">SepalLength</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M281.964,-554.95C271.316,-537.504 258.993,-517.316 247.799,-498.976\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"250.604,-496.853 242.406,-490.141 244.629,-500.5 250.604,-496.853\"/>\n",
"<text text-anchor=\"middle\" x=\"274.519\" y=\"-518.512\" font-family=\"Times,serif\" font-size=\"14.00\">yes</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"395.725,-460.909 286.65,-460.909 286.65,-424.909 395.725,-424.909 395.725,-460.909\"/>\n",
"<text text-anchor=\"middle\" x=\"341.188\" y=\"-438.709\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.0965398</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M319.665,-548.588C324.967,-522.802 331.191,-492.531 335.578,-471.193\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"339.045,-471.707 337.631,-461.207 332.189,-470.297 339.045,-471.707\"/>\n",
"<text text-anchor=\"middle\" x=\"333.188\" y=\"-518.512\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node4\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"174.188\" cy=\"-288.562\" rx=\"49.5881\" ry=\"49.5881\"/>\n",
"<text text-anchor=\"middle\" x=\"174.188\" y=\"-284.362\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;4 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M200.422,-389.48C196.803,-375.697 192.882,-360.761 189.201,-346.743\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"192.496,-345.51 186.571,-336.727 185.725,-347.288 192.496,-345.51\"/>\n",
"<text text-anchor=\"middle\" x=\"203.519\" y=\"-358.906\" font-family=\"Times,serif\" font-size=\"14.00\">yes</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"293.188\" cy=\"-288.562\" rx=\"49.5881\" ry=\"49.5881\"/>\n",
"<text text-anchor=\"middle\" x=\"293.188\" y=\"-284.362\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M239.184,-393.705C247.727,-377.229 257.322,-358.726 266.028,-341.938\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"269.264,-343.299 270.761,-332.811 263.05,-340.077 269.264,-343.299\"/>\n",
"<text text-anchor=\"middle\" x=\"266.188\" y=\"-358.906\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 8 -->\n",
"<g id=\"node10\" class=\"node\"><title>8</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"104.563,-155.509 -0.188176,-155.509 -0.188176,-119.509 104.563,-119.509 104.563,-155.509\"/>\n",
"<text text-anchor=\"middle\" x=\"52.1875\" y=\"-133.309\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.0165137</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;8 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>4&#45;&gt;8</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M143.086,-249.564C120.983,-222.56 91.9225,-187.055 72.6782,-163.543\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"75.3505,-161.282 66.3082,-155.761 69.9336,-165.716 75.3505,-161.282\"/>\n",
"<text text-anchor=\"middle\" x=\"126.519\" y=\"-209.817\" font-family=\"Times,serif\" font-size=\"14.00\">yes</text>\n",
"</g>\n",
"<!-- 7 -->\n",
"<g id=\"node11\" class=\"node\"><title>7</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"226.563,-155.509 121.812,-155.509 121.812,-119.509 226.563,-119.509 226.563,-155.509\"/>\n",
"<text text-anchor=\"middle\" x=\"174.188\" y=\"-133.309\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.0847059</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;7 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>4&#45;&gt;7</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M174.188,-238.756C174.188,-214.575 174.188,-186.276 174.188,-165.923\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"177.688,-165.789 174.188,-155.789 170.688,-165.789 177.688,-165.789\"/>\n",
"<text text-anchor=\"middle\" x=\"181.188\" y=\"-209.817\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 6 -->\n",
"<g id=\"node6\" class=\"node\"><title>6</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"342.063,-155.509 244.312,-155.509 244.312,-119.509 342.063,-119.509 342.063,-155.509\"/>\n",
"<text text-anchor=\"middle\" x=\"293.188\" y=\"-133.309\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.157732</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;6 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>3&#45;&gt;6</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M293.188,-238.756C293.188,-214.575 293.188,-186.276 293.188,-165.923\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"296.688,-165.789 293.188,-155.789 289.688,-165.789 296.688,-165.789\"/>\n",
"<text text-anchor=\"middle\" x=\"302.519\" y=\"-209.817\" font-family=\"Times,serif\" font-size=\"14.00\">yes</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node7\" class=\"node\"><title>5</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"411.188\" cy=\"-137.509\" rx=\"51.5175\" ry=\"51.5175\"/>\n",
"<text text-anchor=\"middle\" x=\"411.188\" y=\"-133.309\" font-family=\"Times,serif\" font-size=\"14.00\">SepalWidth</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;5 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>3&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M323.575,-249.177C338.767,-229.987 357.298,-206.58 373.398,-186.243\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"376.205,-188.337 379.667,-178.324 370.716,-183.992 376.205,-188.337\"/>\n",
"<text text-anchor=\"middle\" x=\"363.188\" y=\"-209.817\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 10 -->\n",
"<g id=\"node8\" class=\"node\"><title>10</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"402.563,-36 297.812,-36 297.812,-0 402.563,-0 402.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"350.188\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.0219512</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;10 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;10</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M387.778,-91.4129C379.721,-75.8925 370.965,-59.0261 363.933,-45.4789\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"366.865,-43.5306 359.151,-36.2678 360.652,-46.7558 366.865,-43.5306\"/>\n",
"<text text-anchor=\"middle\" x=\"385.519\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes</text>\n",
"</g>\n",
"<!-- 9 -->\n",
"<g id=\"node9\" class=\"node\"><title>9</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"524.563,-36 419.812,-36 419.812,-0 524.563,-0 524.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"472.188\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.0818182</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;9 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5&#45;&gt;9</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M434.597,-91.4129C442.654,-75.8925 451.41,-59.0261 458.442,-45.4789\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"461.723,-46.7558 463.224,-36.2678 455.51,-43.5306 461.723,-46.7558\"/>\n",
"<text text-anchor=\"middle\" x=\"459.188\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x107138710>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.seed(1) \n",
"dm = xgb.DMatrix((np.random.randn(150, 4) > 0).astype(int), label=iris.target,\n",
" feature_names=['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'],\n",
" feature_types=['i', 'i', 'i', 'i'])\n",
"bst = xgb.train(params, dm)\n",
"xgb.to_graphviz(bst)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"650pt\" height=\"817pt\"\n",
" viewBox=\"0.00 0.00 649.71 817.24\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 813.239)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-813.239 645.706,-813.239 645.706,4 -4,4\"/>\n",
"<!-- 0 -->\n",
"<g id=\"node1\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"313.688\" cy=\"-735.937\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"313.688\" y=\"-731.737\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;2.45</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node2\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"307.213,-560.627 206.162,-560.627 206.162,-524.627 307.213,-524.627 307.213,-560.627\"/>\n",
"<text text-anchor=\"middle\" x=\"256.688\" y=\"-538.427\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.215311</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M287.757,-667.19C285.16,-659.624 282.671,-651.994 280.46,-644.634 273.044,-619.951 266.493,-591.311 262.155,-570.845\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"265.561,-570.029 260.096,-560.952 258.708,-571.456 265.561,-570.029\"/>\n",
"<text text-anchor=\"middle\" x=\"315.301\" y=\"-633.434\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node3\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"395.688\" cy=\"-542.627\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"395.688\" y=\"-538.427\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.75</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M342.252,-668.294C349.428,-651.553 357.165,-633.502 364.463,-616.474\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"367.744,-617.705 368.466,-607.135 361.31,-614.947 367.744,-617.705\"/>\n",
"<text text-anchor=\"middle\" x=\"364.688\" y=\"-633.434\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node4\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"304.688\" cy=\"-349.317\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"304.688\" y=\"-345.117\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;4.95</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M365.891,-478.985C357.681,-461.725 348.693,-442.83 340.194,-424.964\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"343.258,-423.256 335.802,-415.729 336.937,-426.263 343.258,-423.256\"/>\n",
"<text text-anchor=\"middle\" x=\"388.301\" y=\"-443.419\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node5\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"469.688\" cy=\"-349.317\" rx=\"73.1049\" ry=\"73.1049\"/>\n",
"<text text-anchor=\"middle\" x=\"469.688\" y=\"-345.117\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;4.85</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;4 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M420.637,-477.125C426.775,-461.256 433.41,-444.103 439.757,-427.696\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"443.111,-428.726 443.454,-418.137 436.582,-426.2 443.111,-428.726\"/>\n",
"<text text-anchor=\"middle\" x=\"441.688\" y=\"-443.419\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node6\" class=\"node\"><title>5</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"153.688\" cy=\"-156.007\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"153.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.55</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;5 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>3&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M259.587,-291.177C241.785,-268.623 221.276,-242.639 203.076,-219.58\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"205.686,-217.238 196.743,-211.557 200.191,-221.575 205.686,-217.238\"/>\n",
"<text text-anchor=\"middle\" x=\"264.301\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 6 -->\n",
"<g id=\"node7\" class=\"node\"><title>6</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"311.688\" cy=\"-156.007\" rx=\"70.015\" ry=\"70.015\"/>\n",
"<text text-anchor=\"middle\" x=\"311.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;1.55</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;6 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>3&#45;&gt;6</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M307.334,-275.991C307.804,-263.133 308.297,-249.677 308.774,-236.63\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"312.285,-236.395 309.153,-226.273 305.29,-236.139 312.285,-236.395\"/>\n",
"<text text-anchor=\"middle\" x=\"315.688\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 7 -->\n",
"<g id=\"node12\" class=\"node\"><title>7</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"521.601,-174.007 401.774,-174.007 401.774,-138.007 521.601,-138.007 521.601,-174.007\"/>\n",
"<text text-anchor=\"middle\" x=\"461.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;7.66345e&#45;09</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;7 -->\n",
"<g id=\"edge11\" class=\"edge\"><title>4&#45;&gt;7</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M466.663,-275.991C465.32,-243.876 463.821,-208.024 462.823,-184.151\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"466.316,-183.927 462.402,-174.082 459.322,-184.22 466.316,-183.927\"/>\n",
"<text text-anchor=\"middle\" x=\"500.301\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 8 -->\n",
"<g id=\"node13\" class=\"node\"><title>8</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"641.725,-174.007 539.65,-174.007 539.65,-138.007 641.725,-138.007 641.725,-174.007\"/>\n",
"<text text-anchor=\"middle\" x=\"590.688\" y=\"-151.807\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.213812</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;8 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>4&#45;&gt;8</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M515.428,-291.602C523.528,-280.697 531.621,-269.187 538.688,-258.015 554.069,-233.695 568.807,-204.289 578.64,-183.493\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"581.866,-184.857 582.926,-174.315 575.524,-181.895 581.866,-184.857\"/>\n",
"<text text-anchor=\"middle\" x=\"553.688\" y=\"-246.815\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 9 -->\n",
"<g id=\"node8\" class=\"node\"><title>9</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"97.5632,-36 -0.188225,-36 -0.188225,-0 97.5632,-0 97.5632,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"48.6875\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.428571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;9 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;9</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M111.283,-100.08C96.3954,-80.7964 80.3826,-60.055 68.2796,-44.3779\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"70.8714,-42.0076 61.99,-36.2308 65.3305,-46.2853 70.8714,-42.0076\"/>\n",
"<text text-anchor=\"middle\" x=\"120.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 10 -->\n",
"<g id=\"node9\" class=\"node\"><title>10</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"212.563,-36 114.812,-36 114.812,-0 212.563,-0 212.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"163.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;10 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5&#45;&gt;10</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M158.775,-85.8084C159.806,-71.7847 160.833,-57.8287 161.678,-46.3271\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"165.185,-46.3594 162.428,-36.1296 158.204,-45.846 165.185,-46.3594\"/>\n",
"<text text-anchor=\"middle\" x=\"168.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 11 -->\n",
"<g id=\"node10\" class=\"node\"><title>11</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"342.725,-36 240.65,-36 240.65,-0 342.725,-0 342.725,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"291.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;11 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>6&#45;&gt;11</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M301.629,-86.6053C299.514,-72.2219 297.402,-57.8623 295.673,-46.1004\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"299.12,-45.4871 294.202,-36.1028 292.195,-46.5056 299.12,-45.4871\"/>\n",
"<text text-anchor=\"middle\" x=\"334.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 12 -->\n",
"<g id=\"node11\" class=\"node\"><title>12</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"458.563,-36 360.812,-36 360.812,-0 458.563,-0 458.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"409.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;12 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>6&#45;&gt;12</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M352.397,-98.5096C365.937,-79.7185 380.347,-59.7202 391.327,-44.4806\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"394.358,-46.2621 397.364,-36.1028 388.678,-42.1699 394.358,-46.2621\"/>\n",
"<text text-anchor=\"middle\" x=\"390.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x107138b90>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dm = xgb.DMatrix(iris.data, label=iris.target,\n",
" feature_names=['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'],\n",
" feature_types=['float', 'float', 'float', 'float'])\n",
"np.random.seed(1) \n",
"bst = xgb.train(params, dm)\n",
"xgb.to_graphviz(bst, num_trees=1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"621pt\" height=\"729pt\"\n",
" viewBox=\"0.00 0.00 620.71 728.80\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 724.804)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-724.804 616.706,-724.804 616.706,4 -4,4\"/>\n",
"<!-- 0 -->\n",
"<g id=\"node1\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"296.688\" cy=\"-658.556\" rx=\"62.4967\" ry=\"62.4967\"/>\n",
"<text text-anchor=\"middle\" x=\"296.688\" y=\"-654.356\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;3</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node2\" class=\"node\"><title>1</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"292.213,-505.355 191.162,-505.355 191.162,-469.355 292.213,-469.355 292.213,-505.355\"/>\n",
"<text text-anchor=\"middle\" x=\"241.688\" y=\"-483.155\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.215311</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M269.558,-602.33C266.208,-594.38 263.056,-586.213 260.46,-578.308 253.71,-557.752 248.844,-533.73 245.759,-515.684\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"249.172,-514.868 244.108,-505.562 242.264,-515.995 249.172,-514.868\"/>\n",
"<text text-anchor=\"middle\" x=\"295.301\" y=\"-567.108\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node3\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"369.688\" cy=\"-487.355\" rx=\"58.9063\" ry=\"58.9063\"/>\n",
"<text text-anchor=\"middle\" x=\"369.688\" y=\"-483.155\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;2</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M320.995,-601.215C327.895,-585.223 335.451,-567.709 342.509,-551.35\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"345.851,-552.44 346.598,-541.871 339.423,-549.667 345.851,-552.44\"/>\n",
"<text text-anchor=\"middle\" x=\"342.688\" y=\"-567.108\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node4\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"292.688\" cy=\"-316.154\" rx=\"62.4967\" ry=\"62.4967\"/>\n",
"<text text-anchor=\"middle\" x=\"292.688\" y=\"-311.954\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;5</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M339.63,-436.324C334.971,-427.802 330.402,-418.943 326.46,-410.402 322.698,-402.251 319.067,-393.552 315.67,-384.866\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"318.92,-383.566 312.081,-375.474 312.381,-386.064 318.92,-383.566\"/>\n",
"<text text-anchor=\"middle\" x=\"361.301\" y=\"-399.202\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node5\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"434.688\" cy=\"-316.154\" rx=\"62.4967\" ry=\"62.4967\"/>\n",
"<text text-anchor=\"middle\" x=\"434.688\" y=\"-311.954\" font-family=\"Times,serif\" font-size=\"14.00\">PetalLength&lt;5</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;4 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M390.612,-431.888C396.451,-416.687 402.864,-399.994 408.946,-384.16\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"412.364,-385.024 412.683,-374.434 405.83,-382.514 412.364,-385.024\"/>\n",
"<text text-anchor=\"middle\" x=\"410.688\" y=\"-399.202\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node6\" class=\"node\"><title>5</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"158.688\" cy=\"-144.953\" rx=\"58.9063\" ry=\"58.9063\"/>\n",
"<text text-anchor=\"middle\" x=\"158.688\" y=\"-140.753\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;2</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;5 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>3&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M249.953,-270.414C239.973,-259.387 229.597,-247.429 220.46,-235.906 212.3,-225.615 204.029,-214.301 196.306,-203.272\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"199.089,-201.143 190.518,-194.916 193.335,-205.129 199.089,-201.143\"/>\n",
"<text text-anchor=\"middle\" x=\"255.301\" y=\"-224.706\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 6 -->\n",
"<g id=\"node7\" class=\"node\"><title>6</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"294.688\" cy=\"-144.953\" rx=\"58.9063\" ry=\"58.9063\"/>\n",
"<text text-anchor=\"middle\" x=\"294.688\" y=\"-140.753\" font-family=\"Times,serif\" font-size=\"14.00\">PetalWidth&lt;2</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;6 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>3&#45;&gt;6</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M293.415,-253.59C293.566,-240.841 293.726,-227.336 293.879,-214.359\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"297.382,-214.13 294,-204.089 290.382,-214.047 297.382,-214.13\"/>\n",
"<text text-anchor=\"middle\" x=\"301.688\" y=\"-224.706\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 7 -->\n",
"<g id=\"node12\" class=\"node\"><title>7</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"492.601,-162.953 372.774,-162.953 372.774,-126.953 492.601,-126.953 492.601,-162.953\"/>\n",
"<text text-anchor=\"middle\" x=\"432.688\" y=\"-140.753\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;7.66345e&#45;09</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;7 -->\n",
"<g id=\"edge11\" class=\"edge\"><title>4&#45;&gt;7</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M433.96,-253.59C433.633,-225.945 433.264,-194.748 433.008,-173.085\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"436.507,-172.942 432.889,-162.984 429.507,-173.025 436.507,-172.942\"/>\n",
"<text text-anchor=\"middle\" x=\"468.301\" y=\"-224.706\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 8 -->\n",
"<g id=\"node13\" class=\"node\"><title>8</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"612.725,-162.953 510.65,-162.953 510.65,-126.953 612.725,-126.953 612.725,-162.953\"/>\n",
"<text text-anchor=\"middle\" x=\"561.688\" y=\"-140.753\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.213812</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;8 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>4&#45;&gt;8</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M477.719,-270.742C487.653,-259.703 497.881,-247.657 506.688,-235.906 522.018,-215.45 536.991,-190.542 547.433,-172.128\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"550.629,-173.584 552.459,-163.148 544.521,-170.165 550.629,-173.584\"/>\n",
"<text text-anchor=\"middle\" x=\"523.688\" y=\"-224.706\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 9 -->\n",
"<g id=\"node8\" class=\"node\"><title>9</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"97.5632,-36 -0.188225,-36 -0.188225,-0 97.5632,-0 97.5632,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"48.6875\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.428571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;9 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>5&#45;&gt;9</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M118.809,-100.878C109.111,-90.2167 98.8346,-78.7632 89.46,-68 82.841,-60.4007 75.772,-52.0077 69.4105,-44.3472\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"71.9077,-41.8745 62.8402,-36.3944 66.5111,-46.333 71.9077,-41.8745\"/>\n",
"<text text-anchor=\"middle\" x=\"124.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 10 -->\n",
"<g id=\"node9\" class=\"node\"><title>10</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"212.563,-36 114.812,-36 114.812,-0 212.563,-0 212.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"163.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;10 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>5&#45;&gt;10</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M161.012,-85.8662C161.561,-72.1499 162.121,-58.1501 162.586,-46.5286\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"166.096,-46.3341 162.999,-36.2021 159.102,-46.0541 166.096,-46.3341\"/>\n",
"<text text-anchor=\"middle\" x=\"169.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"<!-- 11 -->\n",
"<g id=\"node10\" class=\"node\"><title>11</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"336.725,-36 234.65,-36 234.65,-0 336.725,-0 336.725,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"285.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=&#45;0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;11 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>6&#45;&gt;11</title>\n",
"<path fill=\"none\" stroke=\"#0000ff\" d=\"M290.504,-85.8662C289.516,-72.1499 288.507,-58.1501 287.67,-46.5286\"/>\n",
"<polygon fill=\"#0000ff\" stroke=\"#0000ff\" points=\"291.136,-45.9248 286.927,-36.2021 284.154,-46.4277 291.136,-45.9248\"/>\n",
"<text text-anchor=\"middle\" x=\"324.301\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">yes, missing</text>\n",
"</g>\n",
"<!-- 12 -->\n",
"<g id=\"node11\" class=\"node\"><title>12</title>\n",
"<polygon fill=\"none\" stroke=\"black\" points=\"452.563,-36 354.812,-36 354.812,-0 452.563,-0 452.563,-36\"/>\n",
"<text text-anchor=\"middle\" x=\"403.688\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">leaf=0.128571</text>\n",
"</g>\n",
"<!-- 6&#45;&gt;12 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>6&#45;&gt;12</title>\n",
"<path fill=\"none\" stroke=\"#ff0000\" d=\"M333.776,-100.796C343.305,-90.1375 353.421,-78.7056 362.688,-68 369.298,-60.3629 376.394,-51.959 382.792,-44.3001\"/>\n",
"<polygon fill=\"#ff0000\" stroke=\"#ff0000\" points=\"385.699,-46.2785 389.407,-36.3534 380.319,-41.8004 385.699,-46.2785\"/>\n",
"<text text-anchor=\"middle\" x=\"381.688\" y=\"-56.8\" font-family=\"Times,serif\" font-size=\"14.00\">no</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.dot.Digraph at 0x107138750>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dm = xgb.DMatrix(iris.data, label=iris.target,\n",
" feature_names=['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth'],\n",
" feature_types=['int', 'int', 'int', 'int'])\n",
"np.random.seed(1) \n",
"bst = xgb.train(params, dm)\n",
"xgb.to_graphviz(bst, num_trees=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment