# js-decisiontree

> NodeJS Implementation of Decision Tree using ID3 Algorithm.

Latest version **1.0.1** (published 2020-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install js-decisiontree
pnpm add js-decisiontree
yarn add js-decisiontree
bun add js-decisiontree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-01-17 |
| First published | 2020-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 2 |
| Unpacked size | 21.4 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | Pawan Wagh |
| Maintainers | pawan_prodio |

## Links

- npm: https://www.npmjs.com/package/js-decisiontree
- npm.io page: https://npm.io/package/js-decisiontree

## Dependencies (2)

- [is](https://npm.io/package/is.md) ^3.3.0
- [lodash](https://npm.io/package/lodash.md) ^2.4.2

## Recent versions

- 1.0.1 (latest) — 2020-01-17
- 1.0.0 — 2020-01-17

## README

# DecisionTree
NodeJS Implementation of Decision Tree using ID3 Algorithm. Base decision tree based on [this github repo.](https://github.com/serendipious/nodejs-decision-tree-id3)

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)

Features:

  - Simple APIs
  - Debug mode
  - Inbuilt persist model capability
  - Highly configurable
  - Trained model can be imported/exported easily

### Installation

Dillinger requires [Node.js](https://nodejs.org/) v6+ to run.

```sh
$ npm install js-decisiontree --save
```

### How to use
```js
const { Tree } = require('js-decisiontree');
const trainingDataSet = [];
const config = {};
const DecisionTree = new Tree(config);
DecisionTree.train(trainingDataSet, config);
DecisionTree.predict(sample);
```
### Configuration settings

| Setting | Description |
| ------ | ------ |
| className | Class name or property which will be used as output of decision tree|
| features | Features or data points to be used for training decision tree |
| persist | If set, persists the trained model on local disk |
| learn | If set, trains the model with data used for prediction |
| fixMissingFeatures | If set, takes careof of missing features in training data |
| debug | If set, logs the internal activity to terminal |
| load | If set, loads previously stored model to local disk. This setting is only significant while intializing the tree |

### APIs

| Setting | Description |
| ------ | ------ |
| train | Training the decision tree|
| predict | Prediciting the results |
| toJSON | Export the trained model as JSON |
| fromJSON | Import an already trained JSON model exported using .toJSON() API |

# Examples
 Refer examples for exhautive examples
```js
const DecisionTree = new Tree();
const trainingDataSet = [
    {"color":"blue", "shape":"square", "liked":false},
  	{"color":"red", "shape":"square", "liked":false},
  	{"color":"blue", "shape":"circle", "liked":true},
  	{"color":"red", "shape":"circle", "liked":true},
  	{"color":"blue", "shape":"hexagon", "liked":false},
  	{"color":"red", "shape":"hexagon", "liked":false},
  	{"color":"yellow", "shape":"hexagon", "liked":true},
  	{"color":"yellow", "shape":"circle", "liked":true}
];
const config = {
    className: 'liked',
    features: [ 'color', 'shape' ],
};
const sample = {"color":"blue", "shape":"hexagon", "liked":false }; 
DecisionTree.train(trainingDataSet, config);
const prediction = DecisionTree.predict(sample);
console.log("prediction:", prediction); // false
```

License
----

MIT


**Free Software, Hell Yeah!**

---
_Source: https://npm.io/package/js-decisiontree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
