Package Exports
- decision-tree
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (decision-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Decision Tree for NodeJS
This module contains the NodeJS Implementation of Decision Tree using ID3 Algorithm
Installation
npm install decision-tree
Usage
Import the module:
var DecisionTree = require('decision-tree');
Prepare training dataset:
var training_data = [ {"color":"blue", "shape":"square", "liked":false}, {"color":"red", "shape":"square", "liked":false}, {"color":"blue", "shape":"circle", "liked":true}, {"color":"red", "shape":"circle", "liked":true}, {"color":"blue", "shape":"hexagon", "liked":false}, {"color":"red", "shape":"hexagon", "liked":false}, {"color":"yellow", "shape":"hexagon", "liked":true}, {"color":"yellow", "shape":"circle", "liked":true} ];
Prepare test dataset:
var test_data = [ {"color":"blue", "shape":"hexagon", "liked":false}, {"color":"red", "shape":"hexagon", "liked":false}, {"color":"yellow", "shape":"hexagon", "liked":true}, {"color":"yellow", "shape":"circle", "liked":true} ];
Setup Target Class used for prediction:
var class_name = "liked";
Setup Features to be used by decision tree:
var features = ["color", "shape"];
Create decision tree and train model:
var dt = new DecisionTree(training_data, class_name, features);
Predict class label for an instance:
var predicted_class = dt.predict({ color: "blue", shape: "hexagon" });
Evaluate model on a dataset:
var accuracy = dt.evaluate(test_data);
Export underlying model for visualization or inspection:
var treeModel = dt.toJSON();