1.0.2 • Published 2 years ago

decision-tree-ts v1.0.2

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

decision-tree-ts

Basic, dependency-free and light-weight decision tree algorithm npm-module, use with both TypeScript and JavaScript! Currently only included algorithm is CART.

Features

  • DecisionTree-class, check Quick start to check how to use.
    • Currently only CART-algorithm is supported.
    • Functions fit and predict are public for your use.
    • Currently only numerical features supported.
  • JSDoc included to make the use of the module as easy as possible.
  • To get some useful functions, check out my other repository. I am not going to redo them for this module.
  • Package is tested to be working. Module linear-regression-ts utilized in tests.

Quick start

npm install decision-tree-ts
// Initialize the tree with parameters maxDepth, minSplit.
const tree = DecisionTree(10, 2)
// Training data.
const data = [
    [1, 3],
    [2, 3],
    [3, 1],
    [3, 1],
    [2, 3],
]
const labels = [1, 1, 2, 2, 3]
// Train the model by giving the training data and their labels. 
tree.fit(data, labels)
// Prediction data.
const predictThisData = [
    [1, 3],
    [2, 3],
    [3, 1],
    [3, 1]
]
// Predict labels for your data.
const predictedLabels = tree.predict(predictThisData)
console.log(predictedLabels)

Sources

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago