Skip to content

Predict unknown values with the decision tree (CART) algorithm, with JavaScript and TypeScript!

License

Notifications You must be signed in to change notification settings

olliglorioso/decision-tree-ts

Repository files navigation

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

About

Predict unknown values with the decision tree (CART) algorithm, with JavaScript and TypeScript!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published