Binary Decision Trees

Overview


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

Training the Decision Tree


The binary tree is constructed one level at a time. At each iteration of the training algorithm, the tree will iterate through all the available columns, and all the available values for each column, and select the one that reduces the loss the most.

Loss functions for a binary tree are referred to as impurity measures. The common impurity measures are

  • gini
  • weighted gini

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