Skip to content

Create decision trees and use them to predict new cases.

Notifications You must be signed in to change notification settings

thewizarodofoz/decision-trees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

decision-trees

Create decision trees and use them to predict new cases.

Currently implemented ID3 algorithm only. Based on lectures of Victor Lavrenko

Usage

const ID3 = require('decision-trees');

const examples = [
    {outlook: 'sunny', humidity: 'high', wind: 'weak', play: false},
    {outlook: 'sunny', humidity: 'high', wind: 'strong', play: false},
    {outlook: 'overcast', humidity: 'high', wind: 'weak', play: true},
    {outlook: 'rain', humidity: 'high', wind: 'weak', play: true},
    {outlook: 'rain', humidity: 'normal', wind: 'weak', play: true},
    {outlook: 'rain', humidity: 'normal', wind: 'strong', play: false},
    {outlook: 'overcast', humidity: 'normal', wind: 'strong', play: true},
    {outlook: 'sunny', humidity: 'high', wind: 'weak', play: false},
    {outlook: 'sunny', humidity: 'normal', wind: 'weak', play: true},
    {outlook: 'rain', humidity: 'normal', wind: 'weak', play: true},
    {outlook: 'sunny', humidity: 'normal', wind: 'strong', play: true},
    {outlook: 'overcast', humidity: 'high', wind: 'strong', play: true},
    {outlook: 'overcast', humidity: 'normal', wind: 'weak', play: true},
    {outlook: 'rain', humidity: 'high', wind: 'strong', play: false},
];

let tree = ID3.createTree(examples, 'play', example => example.play);
let label = tree.classify({outlook: 'sunny', humidity: 'high', wind: 'weak'});

API

ID3.createTree(dataset, targetAttribute, predicate) => Tree

Returns a Tree object created from the training dataset.

  • dataset - object array. The training dataset for creating the tree.
  • targetAttribute - string. The attribute of each item in the dataset which defines the class this test case belongs to.
  • predicate - function (optional). Must be of the form example => boolean. If supplied, will be used to determine the class each case belongs to. This is helpful if the target attribute is continuous. If ommited, the default predicate will be used example => example[targetAttribute].

Tree.classify(case) => boolean

Returns a boolean indicating the label of the case according to the target attribute used when creating the tree.

  • case - object. Must be similar to the objects used when creating the tree.

About

Create decision trees and use them to predict new cases.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published