decision-tree-ts
v1.0.2
Published
TS/JS npm module to train and use a decision tree machine learning model.
Downloads
3
Readme
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
- Template (configurations, structure): https://github.com/olliglorioso/typescript-npm-base