ml-cart
v2.1.1
Published
CART decision tree algorithm
Downloads
24,308
Readme
ml-cart (Classification and regression trees)
Decision trees using CART implementation.
Installation
npm i ml-cart
API documentation
Usage
As a classifier
import irisDataset from 'ml-dataset-iris';
import { DecisionTreeClassifier as DTClassifier } from 'ml-cart';
const trainingSet = irisDataset.getNumbers();
const predictions = irisDataset
.getClasses()
.map((elem) => irisDataset.getDistinctClasses().indexOf(elem));
const options = {
gainFunction: 'gini',
maxDepth: 10,
minNumSamples: 3,
};
const classifier = new DTClassifier(options);
classifier.train(trainingSet, predictions);
const result = classifier.predict(trainingSet);
As a regression
import { DecisionTreeRegression as DTRegression } from 'ml-cart';
const x = new Array(100);
const y = new Array(100);
const val = 0.0;
for (let i = 0; i < x.length; ++i) {
x[i] = val;
y[i] = Math.sin(x[i]);
val += 0.01;
}
const reg = new DTRegression();
reg.train(x, y);
const estimations = reg.predict(x);