0.1.9 • Published 1 year ago

@rhodri_davies/decision-tree-js v0.1.9

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

JavaScript DecisionTree

When building the decision tree you must provide both the training data and the feature names. Do not provide a name for your label column as it is assumed that the last column in the training data represents the labels.

The DecisionTree class has a function named predict that will return an object containing class and rule. Class is the predicted label and rule is the associated rule.

Installation

npm i @rhodri_davies/decision-tree-js

Example usage

import { DecisionTree } from '@rhodri_davies/decision-tree-js'


var trainingData = [
    ['Green', 3, 'Apple'],
    ['Yellow', 3, 'Apple'],
    ['Red', 1, 'Grape'],
    ['Red', 1, 'Grape'],
    ['Yellow', 3, 'Lemon'],
]

var headers = ["color", "diameter"]

var decisionTree = new DecisionTree(trainingData, headers)

var prediction = decisionTree.predict(['Green', 3])

console.log(prediction.class)

console.log(prediction.rule)

Console log

{ Apple: '100%' }
[ 'diameter is greater than or equal to 3', "color isn't Yellow" ]
0.1.8

1 year ago

0.1.9

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago