Binary Decision Trees

Overview


A binary tree is a tree where every node either has 0 or 2 children.

Impurity Measure


An impurity measure is a measure that returns a score for a tree, based on how many samples it mis-classifies (hence the name impurity). The

  • gini
  • weighted gini

Training the Decision Tree


The binary classification will iterate through all the available columns in the tree, and all the available values for each column. I constructs a binary decision based on the available values and tests the effectiveness by computing the impurity score. The best binary decision is the one that has the smallest impurity score.

Example


The following example demonstrates using the binary tree api to classify the given data.



let tr = await import('/lib/machine-learning/tree/v1.0.0/binary.mjs');

let data = [
	{popcorn:true, soda:true, age:7,ice:false},
	{popcorn:true, soda:false, age:12,ice:false},
	{popcorn:false, soda:true, age:18,ice:true},
	{popcorn:false, soda:true, age:35,ice:true},
	{popcorn:true, soda:true, age:38,ice:true},
	{popcorn:true, soda:false, age:50,ice:false},
	{popcorn:false, soda:false, age:83,ice:false},
];

let tree = tr.learn(tr.gini,'ice', data);

let classify = tr.classify({
	popcorn:true, soda:true, age:15
}, tree);
					
Try it

Contents