@rhodri_davies/decision-tree-js
v0.1.9
Published
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.
Readme
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-jsExample 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" ]