Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

ml-cart

2.0.1 • Public • Published

ml-cart (Classification and regression trees)

NPM version build status Test coverage npm download

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';
 
var trainingSet = irisDataset.getNumbers();
var predictions = irisDataset
  .getClasses()
  .map((elem) => irisDataset.getDistinctClasses().indexOf(elem));
 
var options = {
  gainFunction: 'gini',
  maxDepth: 10,
  minNumSamples: 3
};
 
var classifier = new DTClassifier(options);
classifier.train(trainingSet, predictions);
var result = classifier.predict(trainingSet);

As a regression

import { DecisionTreeRegression as DTRegression } from 'ml-cart';
 
var x = new Array(100);
var y = new Array(100);
var val = 0.0;
for (var i = 0; i < x.length; ++i) {
  x[i] = val;
  y[i] = Math.sin(x[i]);
  val += 0.01;
}
 
var reg = new DTRegression();
reg.train(x, y);
var estimations = reg.predict(x);

License

MIT

Install

npm i ml-cart

DownloadsWeekly Downloads

270

Version

2.0.1

License

MIT

Unpacked Size

40.7 kB

Total Files

10

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar