Decision trees using CART implementation.
npm i ml-cart
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);
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);