1.0.1 • Published 4 years ago

js-decisiontree v1.0.1

Weekly downloads
2
License
MIT
Repository
-
Last release
4 years ago

DecisionTree

NodeJS Implementation of Decision Tree using ID3 Algorithm. Base decision tree based on this github repo.

Build Status

Features:

  • Simple APIs
  • Debug mode
  • Inbuilt persist model capability
  • Highly configurable
  • Trained model can be imported/exported easily

Installation

Dillinger requires Node.js v6+ to run.

$ npm install js-decisiontree --save

How to use

const { Tree } = require('js-decisiontree');
const trainingDataSet = [];
const config = {};
const DecisionTree = new Tree(config);
DecisionTree.train(trainingDataSet, config);
DecisionTree.predict(sample);

Configuration settings

SettingDescription
classNameClass name or property which will be used as output of decision tree
featuresFeatures or data points to be used for training decision tree
persistIf set, persists the trained model on local disk
learnIf set, trains the model with data used for prediction
fixMissingFeaturesIf set, takes careof of missing features in training data
debugIf set, logs the internal activity to terminal
loadIf set, loads previously stored model to local disk. This setting is only significant while intializing the tree

APIs

SettingDescription
trainTraining the decision tree
predictPrediciting the results
toJSONExport the trained model as JSON
fromJSONImport an already trained JSON model exported using .toJSON() API

Examples

Refer examples for exhautive examples

const DecisionTree = new Tree();
const trainingDataSet = [
    {"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}
];
const config = {
    className: 'liked',
    features: [ 'color', 'shape' ],
};
const sample = {"color":"blue", "shape":"hexagon", "liked":false }; 
DecisionTree.train(trainingDataSet, config);
const prediction = DecisionTree.predict(sample);
console.log("prediction:", prediction); // false

License

MIT

Free Software, Hell Yeah!

1.0.1

4 years ago

1.0.0

4 years ago