Skip to content

Instantly share code, notes, and snippets.

@ashenfad
Last active December 15, 2015 08:59
Show Gist options
  • Save ashenfad/5235229 to your computer and use it in GitHub Desktop.
Save ashenfad/5235229 to your computer and use it in GitHub Desktop.
BigML Tree - Pima Diabetes Data

A sunburst visualization of a BigML decision tree built on the Pima diabetes dataset.

The initial center circle represents the root of the tree. Each outer circle contains the children of the inner circle's nodes. The number of training instances captured by a node determine its arc length (or its size in radians).

Clicking on a node will zoom in to the subtree. After zooming in, selecting the new center point will zoom out one level.

{"public_dataset": false, "code": 200, "locale": "en-US", "short_url": "", "image": "gallery/model.png", "job_type": 400, "private": true, "dataset": "dataset/514fb48a0c0b5e04c300009b", "fields_meta": {"count": 9, "total": 9, "limit": 1000, "offset": 0}, "white_box": false, "dataset_id": "514fb48a0c0b5e04c300009b", "randomize": false, "id": "514fb499035d0731c300004c", "number_of_predictions": 0, "category": 0, "modified_fields": {}, "rows": 768, "out_of_bag": false, "ordering": 0, "fields_to_show": [{"optype": "numeric", "is_objective": false, "name": "pregnancies", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "3.85"], ["Median", "2.97"], ["Maximum", "17.00"], ["Std dev", "3.37"]], "id": "000000", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "plasma glucose", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "120.89"], ["Median", "116.86"], ["Maximum", "199.00"], ["Std dev", "31.97"]], "id": "000001", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "blood pressure", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "69.11"], ["Median", "71.43"], ["Maximum", "122.00"], ["Std dev", "19.36"]], "id": "000002", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "triceps skin thickness", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "20.54"], ["Median", "22.81"], ["Maximum", "99.00"], ["Std dev", "15.95"]], "id": "000003", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "insulin", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "79.80"], ["Median", "30.50"], ["Maximum", "846.00"], ["Std dev", "115.24"]], "id": "000004", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "bmi", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.00"], ["Mean", "31.99"], ["Median", "32.04"], ["Maximum", "67.10"], ["Std dev", "7.88"]], "id": "000005", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "diabetes pedigree", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "0.08"], ["Mean", "0.47"], ["Median", "0.37"], ["Maximum", "2.42"], ["Std dev", "0.33"]], "id": "000006", "css": "numeric type_label datatype-tooltip"}, {"optype": "numeric", "is_objective": false, "name": "age", "datatype_name": "Numeric", "tooltip": "Numeric", "stats": [["Minimum", "21.00"], ["Mean", "33.24"], ["Median", "29.09"], ["Maximum", "81.00"], ["Std dev", "11.76"]], "id": "000007", "css": "numeric type_label datatype-tooltip"}, {"optype": "categorical", "is_objective": true, "name": "diabetes", "datatype_name": "Categorical", "tooltip": "Categorical", "id": "000008", "css": "categorical type_label datatype-tooltip"}], "views": 0, "size": 26191, "range": [1, 768], "credits_per_prediction": 0.0, "source": "source/514fb482035d0731bf000043", "number_of_public_predictions": 0, "sample_rate": 1.0, "objective_fields": ["000008"], "user_name": "ashenfad", "columns": 9, "selective_pruning": false, "status": {"progress": 1.0, "message": "The model has been created", "code": 5, "elapsed": 1646}, "updated": "2013-03-25T02:21:14.919000", "description": "", "tags": [], "price": 0.0, "excluded_fields": [], "cloned": false, "credits": 0.09991073608398438, "stat_pruning": true, "objective_field": "000008", "clones": 0, "resource": "model/514fb499035d0731c300004c", "name": "Diabetes Model", "created": "Mon, 25 Mar 2013 02:21:13 +0000", "url": "", "dataset_status": true, "source_status": true, "number_of_evaluations": 0, "max_columns": 9, "max_rows": 768, "input_fields": ["000000", "000001", "000002", "000003", "000004", "000005", "000006", "000007"], "published": null, "source_id": "514fb482035d0731bf000043", "model": {"kind": "stree", "missing_strategy": "Last prediction", "importance": [["000001", 0.43632], ["000005", 0.22667], ["000007", 0.12099], ["000006", 0.11455], ["000002", 0.03901], ["000003", 0.03464], ["000004", 0.02663], ["000000", 0.00118]], "fields": {"000006": {"optype": "numeric", "name": "diabetes pedigree", "datatype": "double", "preferred": true, "summary": {"sum_squares": 255.20866, "splits": [0.1275, 0.1445, 0.16159, 0.18, 0.197, 0.209, 0.23241, 0.24341, 0.25471, 0.2609, 0.27067, 0.29, 0.30454, 0.32859, 0.3455, 0.3725, 0.39941, 0.42218, 0.45137, 0.4875, 0.52089, 0.551, 0.58645, 0.6265, 0.669, 0.7005, 0.7425, 0.823, 0.8985, 1.028, 1.2545], "missing_count": 0, "sum": 362.401, "median": 0.3725, "maximum": 2.42, "minimum": 0.078, "standard_deviation": 0.33133, "variance": 0.10978, "population": 768, "bins": [[0.09307, 14], [0.14539, 70], [0.19699, 75], [0.25099, 107], [0.29244, 52], [0.34636, 77], [0.41082, 50], [0.45431, 29], [0.50029, 31], [0.54705, 38], [0.59542, 31], [0.64585, 26], [0.6897, 30], [0.74482, 33], [0.82242, 19], [0.87929, 17], [0.94765, 17], [1.015, 5], [1.08729, 7], [1.14571, 7], [1.20238, 8], [1.2702, 5], [1.33067, 3], [1.39375, 4], [1.45933, 3], [1.6, 1], [1.70933, 3], [1.781, 1], [1.893, 1], [2.137, 1], [2.3085, 2], [2.42, 1]], "mean": 0.47188}, "column_number": 6, "order": 6}, "000007": {"optype": "numeric", "name": "age", "datatype": "int8", "preferred": true, "summary": {"sum_squares": 954685, "splits": [21.00793, 21.49815, 21.95822, 22.45075, 23.15535, 23.91238, 24.60085, 25.28338, 26.13665, 27.12428, 28.07187, 29.08726, 30.43864, 31.93845, 33.92911, 36.36267, 38.19211, 40.54937, 42.17071, 44.82629, 48.1, 52.72302, 59.43649], "missing_count": 0, "sum": 25529, "median": 29.08726, "maximum": 81, "minimum": 21, "standard_deviation": 11.76023, "variance": 138.30305, "population": 768, "bins": [[21.53333, 135], [23.54762, 84], [25.40741, 81], [27.52239, 67], [29.42, 50], [31.4, 40], [33.45161, 31], [35.61538, 26], [37.45714, 35], [39.52, 25], [41.45, 40], [43.38095, 21], [45.46429, 28], [47.45455, 11], [49.61538, 13], [51.5, 16], [53.54545, 11], [55.42857, 7], [57.58333, 12], [59.625, 8], [61, 2], [62, 4], [63, 4], [64, 1], [65, 3], [66, 4], [67, 3], [68, 1], [69, 2], [70, 1], [72, 1], [81, 1]], "mean": 33.24089}, "column_number": 7, "order": 7}, "000004": {"optype": "numeric", "name": "insulin", "datatype": "int16", "preferred": true, "summary": {"sum_squares": 15077256, "splits": [0.18843, 30.5, 127.5], "missing_count": 0, "sum": 61286, "median": 30.5, "maximum": 846, "minimum": 0, "standard_deviation": 115.244, "variance": 13281.18008, "population": 768, "bins": [[0, 374], [19.33333, 9], [43.4375, 32], [59.89474, 38], [74.38462, 26], [91.21739, 46], [112.23256, 43], [134.34884, 43], [160.17647, 34], [184.35294, 34], [208.57895, 19], [232, 11], [251.4, 5], [272.7, 10], [288.5, 6], [304.66667, 3], [324.75, 8], [338.5, 2], [368.33333, 3], [393.66667, 3], [415, 1], [440, 1], [465, 1], [479.4, 5], [495, 2], [510, 1], [542.66667, 3], [579, 1], [600, 1], [680, 1], [744, 1], [846, 1]], "mean": 79.79948}, "column_number": 4, "order": 4}, "000005": {"optype": "numeric", "name": "bmi", "datatype": "double", "preferred": true, "summary": {"sum_squares": 833743.95, "splits": [19.95, 22.15, 23.35858, 24.25505, 25, 25.63542, 26.38229, 27.3, 27.76103, 28.45858, 29.06972, 29.76202, 30.175, 30.82974, 31.43175, 32.04325, 32.6366, 33.13956, 33.6263, 34.14142, 34.57, 35.2, 35.7899, 36.56904, 37.41716, 38.17417, 39.1, 40.05858, 42.15858, 43.45, 46.1], "missing_count": 0, "sum": 24570.3, "median": 32.04325, "maximum": 67.1, "minimum": 0, "standard_deviation": 7.88416, "variance": 62.15998, "population": 768, "bins": [[0, 11], [18.25, 4], [19.72308, 13], [21.02222, 9], [22.15909, 22], [23.46333, 30], [24.88947, 57], [26.27568, 37], [27.50732, 41], [28.56341, 41], [29.93333, 63], [31.00645, 31], [32.07755, 49], [33.02683, 41], [34.27692, 78], [35.64474, 38], [36.73939, 33], [38.03721, 43], [39.46061, 33], [40.95263, 19], [42.49444, 18], [43.36923, 13], [44.2625, 8], [45.42727, 11], [46.41111, 9], [48.225, 4], [49.65, 4], [52.675, 4], [55, 1], [57.3, 1], [59.4, 1], [67.1, 1]], "mean": 31.99258}, "column_number": 5, "order": 5}, "000002": {"optype": "numeric", "name": "blood pressure", "datatype": "int8", "preferred": true, "summary": {"sum_squares": 3954989, "splits": [4.95379, 47.79361, 52.45455, 56.31476, 58.78684, 60.12982, 61.72909, 62.88889, 64.03541, 65.06458, 66.38178, 67.65685, 68.70061, 69.62414, 70.48722, 71.43285, 72.48913, 73.49, 74.23488, 75.36578, 76.27906, 77.43376, 78.51858, 79.65375, 80.9007, 82.4098, 84.16186, 85.97598, 88.04005, 90.09226, 94.7101], "missing_count": 0, "sum": 53073, "median": 71.43285, "maximum": 122, "minimum": 0, "standard_deviation": 19.35581, "variance": 374.64727, "population": 768, "bins": [[0, 35], [24, 1], [30, 2], [39, 2], [44.66667, 6], [49.44444, 18], [52, 11], [55.04, 25], [58, 21], [60.95833, 72], [64.8375, 80], [68, 45], [70, 57], [72, 44], [74.86869, 99], [78, 45], [80, 40], [82, 30], [84.96, 50], [88, 25], [90, 22], [92, 8], [94.81818, 11], [98, 3], [100, 3], [102, 1], [104, 2], [106, 3], [108, 2], [110, 3], [114, 1], [122, 1]], "mean": 69.10547}, "column_number": 2, "order": 2}, "000003": {"optype": "numeric", "name": "triceps skin thickness", "datatype": "int8", "preferred": true, "summary": {"sum_squares": 519082, "splits": [0.46227, 13.14087, 22.81344, 29.82784, 36.68115], "missing_count": 0, "sum": 15772, "median": 22.81344, "maximum": 99, "minimum": 0, "standard_deviation": 15.95222, "variance": 254.47325, "population": 768, "bins": [[0, 227], [7.5, 4], [10.54545, 11], [12.61111, 18], [14.7, 20], [16.7, 20], [18.47368, 38], [20.43478, 23], [22.57895, 38], [24.57143, 28], [26.58974, 39], [28.45946, 37], [30.41304, 46], [32.39216, 51], [34.65217, 23], [36.53333, 30], [38.72, 25], [40.48387, 31], [42.35294, 17], [44.54545, 11], [46, 8], [47, 4], [48, 4], [49, 3], [50, 3], [51, 1], [52, 2], [54, 2], [56, 1], [60, 1], [63, 1], [99, 1]], "mean": 20.53646}, "column_number": 3, "order": 3}, "000000": {"optype": "numeric", "name": "pregnancies", "datatype": "int8", "preferred": true, "summary": {"sum_squares": 20063, "missing_count": 0, "sum": 2953, "median": 2.96687, "maximum": 17, "minimum": 0, "standard_deviation": 3.36958, "variance": 11.35406, "counts": [[0, 111], [1, 135], [2, 103], [3, 75], [4, 68], [5, 57], [6, 50], [7, 45], [8, 38], [9, 28], [10, 24], [11, 11], [12, 9], [13, 10], [14, 2], [15, 1], [17, 1]], "population": 768, "mean": 3.84505}, "column_number": 0, "order": 0}, "000001": {"optype": "numeric", "name": "plasma glucose", "datatype": "int16", "preferred": true, "summary": {"sum_squares": 12008759, "splits": [73.4641, 80.66667, 84.54447, 88.29199, 91.05556, 94.06937, 96.48528, 99.20588, 100.75, 102.94511, 105.49074, 107.39491, 109.36701, 111.65834, 114.22967, 116.86008, 119.5, 122.08422, 124.38851, 126.57295, 129.07275, 132.7, 136.75, 140.5, 144.71612, 148.66667, 154.90098, 161.82574, 168.66667, 179.1, 187.58579], "missing_count": 0, "sum": 92847, "median": 116.86008, "maximum": 199, "minimum": 0, "standard_deviation": 31.97262, "variance": 1022.24831, "population": 768, "bins": [[0, 5], [44, 1], [56.66667, 3], [61.5, 2], [67.2, 5], [73.3125, 16], [79.79167, 24], [84.26923, 26], [89.64706, 51], [95.29787, 47], [100.97183, 71], [107.21739, 69], [111.48148, 27], [114.57576, 33], [118.5641, 39], [123.68852, 61], [128.62162, 37], [132.57143, 21], [137.52632, 38], [142.65217, 23], [146.4, 25], [150.92857, 14], [154.5625, 16], [158.15385, 13], [162.4, 15], [166.5, 14], [172, 15], [176.16667, 6], [180.125, 16], [183.5, 6], [188.23077, 13], [195.6875, 16]], "mean": 120.89453}, "column_number": 1, "order": 1}, "000008": {"optype": "categorical", "name": "diabetes", "datatype": "string", "preferred": true, "summary": {"missing_count": 0, "categories": [["false", 500], ["true", 268]]}, "column_number": 8, "order": 8}}, "model_fields": {"000006": {"optype": "numeric", "name": "diabetes pedigree", "datatype": "double", "preferred": true, "column_number": 6, "order": 6}, "000007": {"optype": "numeric", "name": "age", "datatype": "int8", "preferred": true, "column_number": 7, "order": 7}, "000004": {"optype": "numeric", "name": "insulin", "datatype": "int16", "preferred": true, "column_number": 4, "order": 4}, "000005": {"optype": "numeric", "name": "bmi", "datatype": "double", "preferred": true, "column_number": 5, "order": 5}, "000002": {"optype": "numeric", "name": "blood pressure", "datatype": "int8", "preferred": true, "column_number": 2, "order": 2}, "000003": {"optype": "numeric", "name": "triceps skin thickness", "datatype": "int8", "preferred": true, "column_number": 3, "order": 3}, "000000": {"optype": "numeric", "name": "pregnancies", "datatype": "int8", "preferred": true, "column_number": 0, "order": 0}, "000001": {"optype": "numeric", "name": "plasma glucose", "datatype": "int16", "preferred": true, "column_number": 1, "order": 1}, "000008": {"optype": "categorical", "name": "diabetes", "datatype": "string", "preferred": true, "column_number": 8, "order": 8}}, "support_threshold": 0, "split_criterion": "Information gain mix", "root": {"count": 768, "confidence": 0.61665, "predicate": true, "objective_summary": {"categories": [["true", 268], ["false", 500]]}, "output": "false", "children": [{"count": 485, "confidence": 0.76866, "predicate": {"operator": "<=", "field": "000001", "value": 127}, "objective_summary": {"categories": [["true", 94], ["false", 391]]}, "output": "false", "children": [{"count": 214, "confidence": 0.60266, "predicate": {"operator": ">", "field": "000007", "value": 28}, "objective_summary": {"categories": [["true", 71], ["false", 143]]}, "output": "false", "children": [{"count": 41, "confidence": 0.83861, "predicate": {"operator": "<=", "field": "000005", "value": 26.36667}, "objective_summary": {"categories": [["true", 2], ["false", 39]]}, "output": "false", "children": [{"count": 38, "output": "false", "confidence": 0.90819, "predicate": {"operator": ">", "field": "000005", "value": 19.45}, "objective_summary": {"categories": [["false", 38]]}}, {"count": 3, "confidence": 0.20765, "predicate": {"operator": "<=", "field": "000005", "value": 19.45}, "objective_summary": {"categories": [["false", 1], ["true", 2]]}, "output": "true", "children": [{"count": 2, "output": "true", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000006", "value": 0.2725}, "objective_summary": {"categories": [["true", 2]]}}, {"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": ">", "field": "000006", "value": 0.2725}, "objective_summary": {"categories": [["false", 1]]}}]}]}, {"count": 173, "confidence": 0.52675, "predicate": {"operator": ">", "field": "000005", "value": 26.36667}, "objective_summary": {"categories": [["true", 69], ["false", 104]]}, "output": "false", "children": [{"count": 118, "confidence": 0.41122, "predicate": {"operator": ">", "field": "000001", "value": 99}, "objective_summary": {"categories": [["true", 59], ["false", 59]]}, "output": "false", "children": [{"count": 84, "confidence": 0.48834, "predicate": {"operator": "<=", "field": "000006", "value": 0.561}, "objective_summary": {"categories": [["true", 34], ["false", 50]]}, "output": "false", "children": [{"count": 6, "output": "false", "confidence": 0.60966, "predicate": {"operator": ">", "field": "000007", "value": 56}, "objective_summary": {"categories": [["false", 6]]}}, {"count": 78, "confidence": 0.45362, "predicate": {"operator": "<=", "field": "000007", "value": 56}, "objective_summary": {"categories": [["true", 34], ["false", 44]]}, "output": "false", "children": [{"count": 20, "output": "false", "confidence": 0.58398, "predicate": {"operator": "<=", "field": "000006", "value": 0.20025}, "objective_summary": {"categories": [["true", 4], ["false", 16]]}}, {"count": 58, "confidence": 0.39162, "predicate": {"operator": ">", "field": "000006", "value": 0.20025}, "objective_summary": {"categories": [["false", 28], ["true", 30]]}, "output": "true", "children": [{"count": 26, "confidence": 0.4622, "predicate": {"operator": ">", "field": "000003", "value": 26}, "objective_summary": {"categories": [["true", 9], ["false", 17]]}, "output": "false", "children": [{"count": 23, "output": "false", "confidence": 0.5353, "predicate": {"operator": "<=", "field": "000005", "value": 43.1}, "objective_summary": {"categories": [["true", 6], ["false", 17]]}}, {"count": 3, "output": "true", "confidence": 0.43849, "predicate": {"operator": ">", "field": "000005", "value": 43.1}, "objective_summary": {"categories": [["true", 3]]}}]}, {"count": 32, "confidence": 0.48311, "predicate": {"operator": "<=", "field": "000003", "value": 26}, "objective_summary": {"categories": [["false", 11], ["true", 21]]}, "output": "true", "children": [{"count": 24, "output": "true", "confidence": 0.59529, "predicate": {"operator": "<=", "field": "000002", "value": 79}, "objective_summary": {"categories": [["false", 5], ["true", 19]]}}, {"count": 8, "confidence": 0.40927, "predicate": {"operator": ">", "field": "000002", "value": 79}, "objective_summary": {"categories": [["true", 2], ["false", 6]]}, "output": "false", "children": [{"count": 5, "output": "false", "confidence": 0.56551, "predicate": {"operator": ">", "field": "000000", "value": 2}, "objective_summary": {"categories": [["false", 5]]}}, {"count": 3, "confidence": 0.20765, "predicate": {"operator": "<=", "field": "000000", "value": 2}, "objective_summary": {"categories": [["false", 1], ["true", 2]]}, "output": "true", "children": [{"count": 2, "output": "true", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000002", "value": 91}, "objective_summary": {"categories": [["true", 2]]}}, {"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": ">", "field": "000002", "value": 91}, "objective_summary": {"categories": [["false", 1]]}}]}]}]}]}]}]}, {"count": 34, "confidence": 0.56883, "predicate": {"operator": ">", "field": "000006", "value": 0.561}, "objective_summary": {"categories": [["false", 9], ["true", 25]]}, "output": "true", "children": [{"count": 13, "output": "true", "confidence": 0.7719, "predicate": {"operator": ">", "field": "000000", "value": 6}, "objective_summary": {"categories": [["true", 13]]}}, {"count": 21, "confidence": 0.36546, "predicate": {"operator": "<=", "field": "000000", "value": 6}, "objective_summary": {"categories": [["false", 9], ["true", 12]]}, "output": "true", "children": [{"count": 11, "confidence": 0.3538, "predicate": {"operator": "<=", "field": "000004", "value": 120}, "objective_summary": {"categories": [["true", 4], ["false", 7]]}, "output": "false", "children": [{"count": 6, "confidence": 0.29999, "predicate": {"operator": ">", "field": "000007", "value": 34}, "objective_summary": {"categories": [["false", 2], ["true", 4]]}, "output": "true", "children": [{"count": 4, "output": "true", "confidence": 0.5101, "predicate": {"operator": "<=", "field": "000005", "value": 33.15}, "objective_summary": {"categories": [["true", 4]]}}, {"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000005", "value": 33.15}, "objective_summary": {"categories": [["false", 2]]}}]}, {"count": 5, "output": "false", "confidence": 0.56551, "predicate": {"operator": "<=", "field": "000007", "value": 34}, "objective_summary": {"categories": [["false", 5]]}}]}, {"count": 10, "confidence": 0.49016, "predicate": {"operator": ">", "field": "000004", "value": 120}, "objective_summary": {"categories": [["false", 2], ["true", 8]]}, "output": "true", "children": [{"count": 4, "confidence": 0.15004, "predicate": {"operator": ">", "field": "000003", "value": 42}, "objective_summary": {"categories": [["true", 2], ["false", 2]]}, "output": "false", "children": [{"count": 2, "output": "true", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000001", "value": 115}, "objective_summary": {"categories": [["true", 2]]}}, {"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000001", "value": 115}, "objective_summary": {"categories": [["false", 2]]}}]}, {"count": 6, "output": "true", "confidence": 0.60966, "predicate": {"operator": "<=", "field": "000003", "value": 42}, "objective_summary": {"categories": [["true", 6]]}}]}]}]}]}, {"count": 55, "confidence": 0.69669, "predicate": {"operator": "<=", "field": "000001", "value": 99}, "objective_summary": {"categories": [["true", 10], ["false", 45]]}, "output": "false", "children": [{"count": 44, "output": "false", "confidence": 0.76021, "predicate": {"operator": "<=", "field": "000006", "value": 0.716}, "objective_summary": {"categories": [["true", 5], ["false", 39]]}}, {"count": 11, "confidence": 0.28009, "predicate": {"operator": ">", "field": "000006", "value": 0.716}, "objective_summary": {"categories": [["true", 5], ["false", 6]]}, "output": "false", "children": [{"count": 8, "confidence": 0.40927, "predicate": {"operator": ">", "field": "000004", "value": 28}, "objective_summary": {"categories": [["true", 2], ["false", 6]]}, "output": "false", "children": [{"count": 6, "output": "false", "confidence": 0.60966, "predicate": {"operator": "<=", "field": "000004", "value": 85}, "objective_summary": {"categories": [["false", 6]]}}, {"count": 2, "output": "true", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000004", "value": 85}, "objective_summary": {"categories": [["true", 2]]}}]}, {"count": 3, "output": "true", "confidence": 0.43849, "predicate": {"operator": "<=", "field": "000004", "value": 28}, "objective_summary": {"categories": [["true", 3]]}}]}]}]}]}, {"count": 271, "output": "false", "confidence": 0.87587, "predicate": {"operator": "<=", "field": "000007", "value": 28}, "objective_summary": {"categories": [["true", 23], ["false", 248]]}}]}, {"count": 283, "confidence": 0.55697, "predicate": {"operator": ">", "field": "000001", "value": 127}, "objective_summary": {"categories": [["false", 109], ["true", 174]]}, "output": "true", "children": [{"count": 210, "confidence": 0.65474, "predicate": {"operator": ">", "field": "000005", "value": 29.825}, "objective_summary": {"categories": [["false", 59], ["true", 151]]}, "output": "true", "children": [{"count": 117, "confidence": 0.5077, "predicate": {"operator": "<=", "field": "000001", "value": 157}, "objective_summary": {"categories": [["false", 47], ["true", 70]]}, "output": "true", "children": [{"count": 102, "confidence": 0.45243, "predicate": {"operator": ">", "field": "000002", "value": 61}, "objective_summary": {"categories": [["false", 46], ["true", 56]]}, "output": "true", "children": [{"count": 41, "confidence": 0.53016, "predicate": {"operator": "<=", "field": "000007", "value": 30}, "objective_summary": {"categories": [["true", 13], ["false", 28]]}, "output": "false", "children": [{"count": 8, "output": "false", "confidence": 0.67558, "predicate": {"operator": ">", "field": "000004", "value": 271}, "objective_summary": {"categories": [["false", 8]]}}, {"count": 33, "confidence": 0.43683, "predicate": {"operator": "<=", "field": "000004", "value": 271}, "objective_summary": {"categories": [["true", 13], ["false", 20]]}, "output": "false", "children": [{"count": 25, "confidence": 0.52423, "predicate": {"operator": "<=", "field": "000005", "value": 41.7}, "objective_summary": {"categories": [["true", 7], ["false", 18]]}, "output": "false", "children": [{"count": 13, "output": "false", "confidence": 0.66685, "predicate": {"operator": ">", "field": "000002", "value": 73}, "objective_summary": {"categories": [["true", 1], ["false", 12]]}}, {"count": 12, "confidence": 0.25378, "predicate": {"operator": "<=", "field": "000002", "value": 73}, "objective_summary": {"categories": [["false", 6], ["true", 6]]}, "output": "true", "children": [{"count": 3, "output": "true", "confidence": 0.43849, "predicate": {"operator": "<=", "field": "000005", "value": 32.45}, "objective_summary": {"categories": [["true", 3]]}}, {"count": 9, "confidence": 0.3542, "predicate": {"operator": ">", "field": "000005", "value": 32.45}, "objective_summary": {"categories": [["true", 3], ["false", 6]]}, "output": "false", "children": [{"count": 6, "confidence": 0.18761, "predicate": {"operator": ">", "field": "000005", "value": 33.75}, "objective_summary": {"categories": [["false", 3], ["true", 3]]}, "output": "true", "children": [{"count": 4, "confidence": 0.30064, "predicate": {"operator": "<=", "field": "000006", "value": 0.617}, "objective_summary": {"categories": [["false", 1], ["true", 3]]}, "output": "true", "children": [{"count": 3, "output": "true", "confidence": 0.43849, "predicate": {"operator": ">", "field": "000001", "value": 129}, "objective_summary": {"categories": [["true", 3]]}}, {"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": "<=", "field": "000001", "value": 129}, "objective_summary": {"categories": [["false", 1]]}}]}, {"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000006", "value": 0.617}, "objective_summary": {"categories": [["false", 2]]}}]}, {"count": 3, "output": "false", "confidence": 0.43849, "predicate": {"operator": "<=", "field": "000005", "value": 33.75}, "objective_summary": {"categories": [["false", 3]]}}]}]}]}, {"count": 8, "confidence": 0.40927, "predicate": {"operator": ">", "field": "000005", "value": 41.7}, "objective_summary": {"categories": [["false", 2], ["true", 6]]}, "output": "true", "children": [{"count": 4, "confidence": 0.15004, "predicate": {"operator": ">", "field": "000001", "value": 144}, "objective_summary": {"categories": [["false", 2], ["true", 2]]}, "output": "true", "children": [{"count": 2, "output": "true", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000006", "value": 0.373}, "objective_summary": {"categories": [["true", 2]]}}, {"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000006", "value": 0.373}, "objective_summary": {"categories": [["false", 2]]}}]}, {"count": 4, "output": "true", "confidence": 0.5101, "predicate": {"operator": "<=", "field": "000001", "value": 144}, "objective_summary": {"categories": [["true", 4]]}}]}]}]}, {"count": 61, "confidence": 0.5811, "predicate": {"operator": ">", "field": "000007", "value": 30}, "objective_summary": {"categories": [["false", 18], ["true", 43]]}, "output": "true", "children": [{"count": 33, "confidence": 0.6908, "predicate": {"operator": ">", "field": "000006", "value": 0.4295}, "objective_summary": {"categories": [["false", 5], ["true", 28]]}, "output": "true", "children": [{"count": 23, "output": "true", "confidence": 0.79008, "predicate": {"operator": "<=", "field": "000005", "value": 38.6}, "objective_summary": {"categories": [["false", 1], ["true", 22]]}}, {"count": 10, "confidence": 0.31267, "predicate": {"operator": ">", "field": "000005", "value": 38.6}, "objective_summary": {"categories": [["false", 4], ["true", 6]]}, "output": "true", "children": [{"count": 3, "output": "false", "confidence": 0.43849, "predicate": {"operator": ">", "field": "000002", "value": 83}, "objective_summary": {"categories": [["false", 3]]}}, {"count": 7, "confidence": 0.48687, "predicate": {"operator": "<=", "field": "000002", "value": 83}, "objective_summary": {"categories": [["false", 1], ["true", 6]]}, "output": "true", "children": [{"count": 6, "output": "true", "confidence": 0.60966, "predicate": {"operator": "<=", "field": "000006", "value": 1.5025}, "objective_summary": {"categories": [["true", 6]]}}, {"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": ">", "field": "000006", "value": 1.5025}, "objective_summary": {"categories": [["false", 1]]}}]}]}]}, {"count": 28, "confidence": 0.35812, "predicate": {"operator": "<=", "field": "000006", "value": 0.4295}, "objective_summary": {"categories": [["false", 13], ["true", 15]]}, "output": "true", "children": [{"count": 23, "confidence": 0.36811, "predicate": {"operator": "<=", "field": "000005", "value": 45.55}, "objective_summary": {"categories": [["true", 10], ["false", 13]]}, "output": "false", "children": [{"count": 16, "confidence": 0.33178, "predicate": {"operator": ">", "field": "000005", "value": 32.45}, "objective_summary": {"categories": [["false", 7], ["true", 9]]}, "output": "true", "children": [{"count": 3, "output": "true", "confidence": 0.43849, "predicate": {"operator": "<=", "field": "000005", "value": 33.05}, "objective_summary": {"categories": [["true", 3]]}}, {"count": 13, "confidence": 0.29143, "predicate": {"operator": ">", "field": "000005", "value": 33.05}, "objective_summary": {"categories": [["true", 6], ["false", 7]]}, "output": "false", "children": [{"count": 10, "confidence": 0.31267, "predicate": {"operator": ">", "field": "000005", "value": 34.15}, "objective_summary": {"categories": [["false", 4], ["true", 6]]}, "output": "true", "children": [{"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000001", "value": 130}, "objective_summary": {"categories": [["false", 2]]}}, {"count": 8, "confidence": 0.40927, "predicate": {"operator": ">", "field": "000001", "value": 130}, "objective_summary": {"categories": [["false", 2], ["true", 6]]}, "output": "true", "children": [{"count": 3, "confidence": 0.20765, "predicate": {"operator": ">", "field": "000005", "value": 37.25}, "objective_summary": {"categories": [["true", 1], ["false", 2]]}, "output": "false", "children": [{"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000006", "value": 0.2505}, "objective_summary": {"categories": [["false", 2]]}}, {"count": 1, "output": "true", "confidence": 0.20654, "predicate": {"operator": ">", "field": "000006", "value": 0.2505}, "objective_summary": {"categories": [["true", 1]]}}]}, {"count": 5, "output": "true", "confidence": 0.56551, "predicate": {"operator": "<=", "field": "000005", "value": 37.25}, "objective_summary": {"categories": [["true", 5]]}}]}]}, {"count": 3, "output": "false", "confidence": 0.43849, "predicate": {"operator": "<=", "field": "000005", "value": 34.15}, "objective_summary": {"categories": [["false", 3]]}}]}]}, {"count": 7, "confidence": 0.48687, "predicate": {"operator": "<=", "field": "000005", "value": 32.45}, "objective_summary": {"categories": [["true", 1], ["false", 6]]}, "output": "false", "children": [{"count": 1, "output": "true", "confidence": 0.20654, "predicate": {"operator": "<=", "field": "000006", "value": 0.146}, "objective_summary": {"categories": [["true", 1]]}}, {"count": 6, "output": "false", "confidence": 0.60966, "predicate": {"operator": ">", "field": "000006", "value": 0.146}, "objective_summary": {"categories": [["false", 6]]}}]}]}, {"count": 5, "output": "true", "confidence": 0.56551, "predicate": {"operator": ">", "field": "000005", "value": 45.55}, "objective_summary": {"categories": [["true", 5]]}}]}]}]}, {"count": 15, "output": "true", "confidence": 0.70183, "predicate": {"operator": "<=", "field": "000002", "value": 61}, "objective_summary": {"categories": [["false", 1], ["true", 14]]}}]}, {"count": 93, "confidence": 0.78788, "predicate": {"operator": ">", "field": "000001", "value": 157}, "objective_summary": {"categories": [["false", 12], ["true", 81]]}, "output": "true", "children": [{"count": 3, "confidence": 0.20765, "predicate": {"operator": ">", "field": "000004", "value": 629}, "objective_summary": {"categories": [["true", 1], ["false", 2]]}, "output": "false", "children": [{"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": "<=", "field": "000007", "value": 45}, "objective_summary": {"categories": [["false", 2]]}}, {"count": 1, "output": "true", "confidence": 0.20654, "predicate": {"operator": ">", "field": "000007", "value": 45}, "objective_summary": {"categories": [["true", 1]]}}]}, {"count": 90, "output": "true", "confidence": 0.80742, "predicate": {"operator": "<=", "field": "000004", "value": 629}, "objective_summary": {"categories": [["false", 10], ["true", 80]]}}]}]}, {"count": 73, "confidence": 0.57141, "predicate": {"operator": "<=", "field": "000005", "value": 29.825}, "objective_summary": {"categories": [["true", 23], ["false", 50]]}, "output": "false", "children": [{"count": 40, "output": "false", "confidence": 0.70927, "predicate": {"operator": "<=", "field": "000001", "value": 145}, "objective_summary": {"categories": [["true", 6], ["false", 34]]}}, {"count": 33, "confidence": 0.35218, "predicate": {"operator": ">", "field": "000001", "value": 145}, "objective_summary": {"categories": [["false", 16], ["true", 17]]}, "output": "true", "children": [{"count": 4, "output": "false", "confidence": 0.5101, "predicate": {"operator": ">", "field": "000007", "value": 61}, "objective_summary": {"categories": [["false", 4]]}}, {"count": 29, "confidence": 0.40738, "predicate": {"operator": "<=", "field": "000007", "value": 61}, "objective_summary": {"categories": [["false", 12], ["true", 17]]}, "output": "true", "children": [{"count": 4, "output": "false", "confidence": 0.5101, "predicate": {"operator": "<=", "field": "000007", "value": 25}, "objective_summary": {"categories": [["false", 4]]}}, {"count": 25, "confidence": 0.4841, "predicate": {"operator": ">", "field": "000007", "value": 25}, "objective_summary": {"categories": [["false", 8], ["true", 17]]}, "output": "true", "children": [{"count": 13, "confidence": 0.29143, "predicate": {"operator": ">", "field": "000005", "value": 27.1}, "objective_summary": {"categories": [["true", 6], ["false", 7]]}, "output": "false", "children": [{"count": 9, "confidence": 0.3542, "predicate": {"operator": "<=", "field": "000002", "value": 82}, "objective_summary": {"categories": [["false", 3], ["true", 6]]}, "output": "true", "children": [{"count": 2, "output": "false", "confidence": 0.34237, "predicate": {"operator": ">", "field": "000006", "value": 0.4625}, "objective_summary": {"categories": [["false", 2]]}}, {"count": 7, "confidence": 0.48687, "predicate": {"operator": "<=", "field": "000006", "value": 0.4625}, "objective_summary": {"categories": [["false", 1], ["true", 6]]}, "output": "true", "children": [{"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": "<=", "field": "000005", "value": 27.45}, "objective_summary": {"categories": [["false", 1]]}}, {"count": 6, "output": "true", "confidence": 0.60966, "predicate": {"operator": ">", "field": "000005", "value": 27.45}, "objective_summary": {"categories": [["true", 6]]}}]}]}, {"count": 4, "output": "false", "confidence": 0.5101, "predicate": {"operator": ">", "field": "000002", "value": 82}, "objective_summary": {"categories": [["false", 4]]}}]}, {"count": 12, "confidence": 0.64611, "predicate": {"operator": "<=", "field": "000005", "value": 27.1}, "objective_summary": {"categories": [["false", 1], ["true", 11]]}, "output": "true", "children": [{"count": 1, "output": "false", "confidence": 0.20654, "predicate": {"operator": "<=", "field": "000001", "value": 151}, "objective_summary": {"categories": [["false", 1]]}}, {"count": 11, "output": "true", "confidence": 0.74116, "predicate": {"operator": ">", "field": "000001", "value": 151}, "objective_summary": {"categories": [["true", 11]]}}]}]}]}]}]}]}]}, "depth_threshold": 20}, "replacement": false}
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
margin: auto;
position: relative;
width: 960px;
background: #fff;
}
#color-controls {
font: 14px sans-serif;
position: absolute;
right: 10px;
top: 10px;
padding: 3px;
}
#color-controls div {
padding: 4px;
}
#hover-info {
font: 14px sans-serif;
position: absolute;
left: 10px;
top: 10px;
}
#summary-info {
font: 14px sans-serif;
position: absolute;
left: 10px;
bottom: 10px;
font: 12px sans-serif;
}
#summary-info div {
padding: 2px;
}
.split-predicate {
font-weight:bold;
border-bottom: 1px solid #DFDFDF;
padding: 7px;
}
.node-info {
margin-top: 10px;
}
.node-info td {
padding: 2px 7px 2px;
}
</style>
<body>
<div id="color-controls">
<form>
<div>
<input type="radio" name="mode" value="prediction" checked \>
<label>Prediction</label>
</div>
<div>
<input type="radio" name="mode" value="confidence"\>
<label id="cnf">Confidence</label>
</div>
<div>
<input type="radio" name="mode" value="split"\>
<label>Split Field</label>
</div>
</form>
</div>
<div id="hover-info"></div>
<div id="summary-info"></div>
</body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 600,
radius = Math.min(width, height) / 2;
function hover_adjust(d, color) {
return d.hover ? d3.rgb(color).brighter(0.66) : color;
}
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
.append("g")
.attr("transform", "translate(" + width / 2 + "," + (height / 2 + 10) + ")");
var partition = d3.layout.partition().value(function(d) { return d.count; });
var x = d3.scale.linear().range([0, 2 * Math.PI]);
var y = d3.scale.sqrt().range([0, radius]);
var arc = d3.svg.arc()
.startAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x))); })
.endAngle(function(d) { return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx))); })
.innerRadius(function(d) { return Math.max(0, y(d.y)); })
.outerRadius(function(d) { return Math.max(0, y(d.y + d.dy)); });
// Interpolate the scales!
function arcTween(d) {
var xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
yd = d3.interpolate(y.domain(), [d.y, 1]),
yr = d3.interpolate(y.range(), [d.y ? 20 : 0, radius]);
return function(d, i) {
return i
? function(t) { return arc(d); }
: function(t) { x.domain(xd(t)); y.domain(yd(t)).range(yr(t)); return arc(d); };
};
}
function find_minmax(node, attr) {
if (node.children) {
minmaxs = node.children.map(function (n) { return find_minmax(n, attr); });
min = Math.min.apply(null, minmaxs.map(function (mm) {return mm.min}));
max = Math.max.apply(null, minmaxs.map(function (mm) {return mm.max}));
return {"min": Math.min(min, node[attr]), "max": Math.max(max, node[attr])};
} else {
return {"min": node[attr], "max": node[attr]};
}
}
d3.json("diabetes-model.json", function(error, root) {
var model = root.model;
var model_type = model.model_fields[root.objective_field].optype == "categorical" ?
"classification" : "regression";
var minmaxs = {};
if (model_type == "classification") {
minmaxs.confidence = find_minmax(model.root, "confidence");
} else {
// Hacky label switch for regression trees
document.getElementById("cnf").innerHTML = "Expected Error";
minmaxs.expected_error = find_minmax(model.root, "confidence");
minmaxs.output = find_minmax(model.root, "output");
}
var scale_pred = model_type == "classification" ?
d3.scale.category10() :
d3.scale.linear().domain([minmaxs.output.min,
minmaxs.output.max])
.range(["#222", "#2ee"]);
var scale_conf = model_type == "classification" ?
d3.scale.linear().domain([minmaxs.confidence.min,
minmaxs.confidence.max])
.range(["#d33", "#3d3"]) :
d3.scale.linear().domain([minmaxs.expected_error.max,
minmaxs.expected_error.min])
.range(["#d33", "#3d3"]);
var scale_split = d3.scale.category20b();
var color_lookup =
{"prediction": function(d) { return hover_adjust(d, scale_pred(d.output)); },
"confidence": function(d) { return hover_adjust(d, scale_conf(d.confidence)); },
"split": function(d) { return hover_adjust(d, scale_split(d.predicate.field)); } };
var color_fn = color_lookup["prediction"];
var path = svg.selectAll("path")
.data(partition.nodes(root.model.root))
.enter().append("path")
.attr("d", arc)
.style("fill", color_fn)
.style("stroke", "#fff")
.on("click", click)
.on("mouseover", mouseover)
.on("mouseout", mouseout);
var click_in_progress = false;
function click(d) {
mark_hover(d, false);
click_in_progress = true;
path.transition().duration(750).style("fill", color_fn).attrTween("d", arcTween(d));
setTimeout(function() {click_in_progress = false;}, 750);
}
d3.selectAll("input").on("change", change);
function change() {
color_fn = color_lookup[this.value];
path.transition().duration(250).style("fill", color_fn);
}
function mouseover(d) {
var split = d.predicate;
var split_msg = split.field ? model.model_fields[split.field].name + " " +
split.operator + " " + split.value
: "Tree Root";
var conf_msg = {"classification": "Confidence", "regression": "Expected Error"};
var hover = d3.select("#hover-info");
hover.append("div").attr("class", "split-predicate").text(split_msg);
tbody = hover.append("table").attr("class", "node-info").append("tbody");
var output = model_type == "classification" ? d.output : parseFloat(d.output.toFixed(3));
table_add(tbody, "Prediction", output);
table_add(tbody, conf_msg[model_type], parseFloat(d.confidence.toFixed(3)));
table_add(tbody, "Count", d.count);
mark_hover(d, true);
if (!click_in_progress) {
path.style("fill", color_fn);
}
var summ_doc = d3.select("#summary-info");
var summaries = summarize(d);
for (id in summaries) {
if (!summaries.hasOwnProperty(id)) { continue; }
var name = model.model_fields[id].name;
var msg = name;
fs = summaries[id];
if (isNum(fs.min)) {
msg = parseFloat(fs.min.toFixed(3)) + " < " + msg;
}
if (isNum(fs.max)) {
msg += " <= " + parseFloat(fs.max.toFixed(3));
}
if (fs.eq) {
msg += " = " + fs.eq;
} else if (fs.not_eq) {
msg += " !=";
var first = true;
for (category in fs.not_eq) {
if (first) {
first = false;
} else {
msg += "|";
}
if (!fs.not_eq.hasOwnProperty(category)) { continue; }
msg += " " + category;
}
msg = msg;
}
summ_doc.append("div").text(msg);
}
}
function mouseout(d) {
d3.select("#hover-info").html("");
d3.select("#summary-info").html("");
mark_hover(d, false);
if (!click_in_progress) {
path.style("fill", color_fn);
}
}
function mark_hover (d, val) {
if (d.parent) { mark_hover(d.parent, val); };
d.hover = val;
}
});
d3.select(self.frameElement).style("height", height + "px");
function isNum(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function summarize (node) {
var pred = node.predicate;
if (node.parent) {
var summary = summarize(node.parent);
switch(pred.operator) {
case "<=":
if (summary[pred.field]) {
var old_max = summary[pred.field].max;
max = isNum(old_max) ? Math.min(pred.value, old_max) : pred.value;
summary[pred.field].max = max;
} else {
summary[pred.field] = {"max": pred.value};
}
break;
case ">":
if (summary[pred.field]) {
var old_min = summary[pred.field].min;
min = isNum(old_min) ? Math.max(pred.value, old_min) : pred.value;
summary[pred.field].min = min;
} else {
summary[pred.field] = {"min": pred.value};
}
break;
case "=":
summary[pred.field] = {"eq": pred.value};
break;
case "!=":
if (!summary[pred.field]) {
summary[pred.field] = {};
}
if (!summary[pred.field].not_eq) {
summary[pred.field].not_eq = {};
}
summary[pred.field].not_eq[pred.value] = true;
break;
}
return summary;
} else {
return {};
}
}
function table_add (table, field, val) {
var row = table.append("tr");
row.append("td").text(field);
row.append("td").text(val);
return row;
}
</script>
@rajthakur609
Copy link

Can i Create a tree using this json..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment