tree-garden
TypeScript icon, indicating that this package has built-in type declarations

0.7.7 • Public • Published

tree-garden Types and tests

Let`s bring a bit of machine-learning on the web! see tree-garden in action! (docs)

Peek in :

import {
  buildAlgorithmConfiguration,
  growTree,
  getTreeAccuracy,
  prune,
  sampleDataSets,
  dataSet,
  statistics,
  impurity
} from 'tree-garden';


const [training, validation] = dataSet.getDividedSet(sampleDataSets.titanicSet, 0.85);
console.log(`length of validation: ${validation.length}, length of training: ${training.length} `);


const myConfig = buildAlgorithmConfiguration(sampleDataSets.titanicSet, {
  excludedAttributes: ['name', 'ticket', 'embarked', 'cabin'], // exclude some attrs that we do not want to use
  attributes: { pclass: { dataType: 'discrete' }, parch: { dataType: 'discrete' }, sibs: { dataType: 'discrete' } }, // consider some number attributes as discrete values
  getScoreForSplit: impurity.getInformationGainRatioForSplit,
  biggerScoreBetterSplit: true
});

const tree = growTree(myConfig, training);
console.log(`UNPRUNED: Number of nodes,${statistics.getNumberOfTreeNodes(tree)} acc:${getTreeAccuracy(tree, validation, myConfig)}`);
const prunedTree = prune.getPrunedTreeByCostComplexityPruning(tree, sampleDataSets.titanicSet, myConfig);
console.log(`Pruned: Number of nodes,${statistics.getNumberOfTreeNodes(prunedTree)} acc:${getTreeAccuracy(prunedTree, validation, myConfig)}`);

// console.log(JSON.stringify(prunedTree));

Readme

Keywords

Package Sidebar

Install

npm i tree-garden

Weekly Downloads

3

Version

0.7.7

License

MIT

Unpacked Size

665 kB

Total Files

167

Last publish

Collaborators

  • miob