NodeJS Implementation of Decision Tree using ID3 Algorithm

Overview

Decision Tree for Node.js

This Node.js module implements a Decision Tree using the ID3 Algorithm

Installation

npm install decision-tree

Usage

Import the module

var DecisionTree = require('decision-tree');

Prepare training dataset

var training_data = [
  {"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}
];

Prepare test dataset

var test_data = [
  {"color":"blue", "shape":"hexagon", "liked":false},
  {"color":"red", "shape":"hexagon", "liked":false},
  {"color":"yellow", "shape":"hexagon", "liked":true},
  {"color":"yellow", "shape":"circle", "liked":true}
];

Setup Target Class used for prediction

var class_name = "liked";

Setup Features to be used by decision tree

var features = ["color", "shape"];

Create decision tree and train the model

var dt = new DecisionTree(class_name, features);
dt.train(training_data);

Alternately, you can also create and train the tree when instantiating the tree itself:

var dt = new DecisionTree(training_data, class_name, features);

Predict class label for an instance

var predicted_class = dt.predict({
  color: "blue",
  shape: "hexagon"
});

Evaluate model on a dataset

var accuracy = dt.evaluate(test_data);

Export underlying model for visualization or inspection

var treeJson = dt.toJSON();

Create a decision tree from a previously trained model

var treeJson = dt.toJSON();
var preTrainedDecisionTree = new DecisionTree(treeJson);

Alternately, you can also import a previously trained model on an existing tree instance, assuming the features & class are the same:

var treeJson = dt.toJSON();
dt.import(treeJson);
Comments
  • Decision Tree Error

    Decision Tree Error

    There's an error here.

    decision-tree.js:20 root = childNode.child; ^

    TypeError: Cannot read property 'child' of undefined at Object.ID3.predict (/nodejs-decision-tree-id3-master/lib/decision-tree.js:20:23) at Object. (/nodejs-decision-tree-id3-master/example.js:22:34) at Module._compile (module.js:434:26) at Object.Module._extensions..js (module.js:452:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:475:10) at startup (node.js:117:18) at node.js:951:3

    bug 
    opened by kennetham 9
  • Bump y18n from 4.0.0 to 4.0.1

    Bump y18n from 4.0.0 to 4.0.1

    Bumps y18n from 4.0.0 to 4.0.1.

    Changelog

    Sourced from y18n's changelog.

    Change Log

    All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

    5.0.5 (2020-10-25)

    Bug Fixes

    5.0.4 (2020-10-16)

    Bug Fixes

    • exports: node 13.0 and 13.1 require the dotted object form with a string fallback (#105) (4f85d80)

    5.0.3 (2020-10-16)

    Bug Fixes

    • exports: node 13.0-13.6 require a string fallback (#103) (e39921e)

    5.0.2 (2020-10-01)

    Bug Fixes

    5.0.1 (2020-09-05)

    Bug Fixes

    5.0.0 (2020-09-05)

    ⚠ BREAKING CHANGES

    • exports maps are now used, which modifies import behavior.
    • drops Node 6 and 4. begin following Node.js LTS schedule (#89)

    Features

    ... (truncated)

    Commits
    Maintainer changes

    This version was pushed to npm by oss-bot, a new releaser for y18n since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Saving then importing a model gives an error

    Saving then importing a model gives an error

    When saving a model with .toJSON, and later importing it, it generates the following error:

    TypeError: Cannot read property 'length' of undefined

    I triple checked multiple times, this error is very real.

    opened by mysticaltech 1
  • Subsequent declarations screw up the previous models

    Subsequent declarations screw up the previous models

    Hello, when I have 1 model, it works great (dynamic_dt below predicts correctly), but when I declare multiple ones (dynamic_dt, mde_dt, ...etc) the results are not accurate. What is happening here, how can I fix this?

    Screen Shot 2021-02-08 at 6 51 48 PM

    opened by mysticaltech 1
  • Bump lodash from 2.4.2 to 4.17.15

    Bump lodash from 2.4.2 to 4.17.15

    Bumps lodash from 2.4.2 to 4.17.15.

    Release notes

    Sourced from lodash's releases.

    4.0.0

    lodash v4.0.0

    2015 was big year! Lodash became the most depended on npm package, passed 1 billion downloads, & its v3 release saw massive adoption!

    The year was also one of collaboration, as discussions began on merging Lodash & Underscore. Much of Lodash v4 is proofing out the ideas from those discussions. Lodash v4 would not be possible without the collaboration & contributions of the Underscore core team. In the spirit of merging our teams have blended with several members contributing to both libraries.

    For 2016 & lodash v4.0.0 we wanted to cut loose, push forward, & take things up a notch!

    Modern only

    With v4 we’re breaking free from old projects, old environments, & dropping old IE < 9 support!

    4 kB Core

    Lodash’s kitchen-sink size will continue to grow as new methods & functionality are added. However, we now offer a 4 kB (gzipped) core build that’s compatible with Backbone v1.2.4 for folks who want Lodash without lugging around the kitchen sink.

    More ES6

    We’ve continued to embrace ES6 with methods like _.isSymbol, added support for cloning & comparing array buffers, maps, sets, & symbols, converting iterators to arrays, & iterable _(…).

    In addition, we’ve published an es-build & pulled babel-plugin-lodash into core to make tree-shaking a breeze.

    More Modular

    Pop quiz! 📣

    What category path does the bindAll method belong to? Is it

    A) require('lodash/function/bindAll') B) require('lodash/utility/bindAll') C) require('lodash/util/bindAll')

    Don’t know? Well, with v4 it doesn’t matter because now module paths are as simple as

    var bindAll = require('lodash/bindAll');
    

    We’ve also reduced module complexity making it easier to create smaller bundles. This has helped Lodash adoption with libraries like Async & Redux!

    1st Class FP

    With v3 we introduced lodash-fp. We learned a lot & with v4 we decided to pull it into core.

    Now you can get immutable, auto-curried, iteratee-first, data-last methods as simply as

    var _ = require('lodash/fp');
    var object = { 'a': 1 };
    </tr></table> ... (truncated)
    
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Use Lodash to determine equality between objects

    Use Lodash to determine equality between objects

    When comparing 2 objects that have identical properties, == will return false unless it uses recursive matching. Luckily, lodash has a handy feature for this!

    opened by omniphx 1
  • Fixes issue #3

    Fixes issue #3

    If "most dominate feature" route is taken when building the tree then there is no matched childNode in some circumstances, so instead return the only node remaining (which is the result) instead.

    bug 
    opened by scrivna 1
  • Bump lodash from 4.17.15 to 4.17.19

    Bump lodash from 4.17.15 to 4.17.19

    Bumps lodash from 4.17.15 to 4.17.19.

    Release notes

    Sourced from lodash's releases.

    4.17.16

    Commits
    Maintainer changes

    This version was pushed to npm by mathias, a new releaser for lodash since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump lodash from 4.17.11 to 4.17.13

    Bump lodash from 4.17.11 to 4.17.13

    Bumps lodash from 4.17.11 to 4.17.13.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Fix the project license file, add latest lodash and mocha lib version and adapt the code to work with it.

    Fix the project license file, add latest lodash and mocha lib version and adapt the code to work with it.

    • add the right MIT license
    • update the lodash and mocha library to the latest version to fix security vulnerabilities
    • fix the code to use the latest lodash version, provide better block scoping
    opened by lpelov 0
Reinforcement learning using Markov Decision Processes. For JS, written in C++.

Pavlov.js About Pavlov.js uses Markov Decision Processes to implement reinforcement learning. It is written in C++ and compiled to JavaScript. For mor

Nathan Epstein 503 Dec 14, 2022
Fancytree - JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Fancytree Fancytree (sequel of DynaTree 1.x) is a JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkb

Martin Wendt 2.6k Jan 9, 2023
The Google Earth Engine implementation of the BioNet algorithm to estimate biophysical parameters along with their uncertainties.

ee-BioNet The Google Earth Engine implementation of the BioNet algorithm to estimate biophysical parameters along with their uncertainties. Quantifyin

Image Processing Lab (IPL) 21 Oct 30, 2022
Dominating set solver using quantum algorithm Grover

Solution for dominating set problem using improved quantum algorithm Grover, which uses Schoning algorithm for k-SAT problem to accomplish this improvement

Fatemehe Lajevardi 8 Aug 31, 2022
This project will be using various AI and Rule Engine algorithm to detect various attack against a company!

?? Introduction This project will be using various AI and Rule Engine algorithm to detect various attack against a website! ?? Mission After starting

Harish S.G 4 Apr 29, 2022
A CRUD implementation using sequelize, mySQL, NODEJS, Express, JWT and other technologies.

A ideia do projeto é simular o funcionamento do backend de um blog através da implementação de uma aplicação em Node.js usando o pacote sequelize para

Vinicius Savordelli 6 May 11, 2022
Linter for Nix using tree-sitter 🌳 + ❄️

Linter for Nix using tree-sitter ?? + ❄️ This is a simple linter for Nix that uses tree-sitter. I plan on extending it with more detections in the fut

Ben Siraphob 41 Dec 20, 2022
A personal semantic search engine capable of surfacing relevant bookmarks, journal entries, notes, blogs, contacts, and more, built on an efficient document embedding algorithm and Monocle's personal search index.

Revery ?? Revery is a semantic search engine that operates on my Monocle search index. While Revery lets me search through the same database of tens o

Linus Lee 215 Dec 30, 2022
Algorithm visualizer made with React, Material UI and P5JS.

Made with React, P5JS and Material UI. Link https://andresrodriguez55.github.io/algorithmsVisualizer/#/ Description The purpose of doing this was to l

Andres Arturo Rodriguez Calderon 31 Nov 22, 2022
JS_GAME/Algorithm

?? JS_GAME JavaScript 를 이용하여 각종 게임을 만들어보자. (자바스크립트를 사용해서 게임을 만들 수 있음.) 웹페이지를 만드는 것도 좋지만, JS 를 이용하여 간단한 게임을 만들면서 생각의 전환을 해보자. 클론 코딩도 좋다! 하지만, 클론 코딩 후에

LEEJAE-GO 2 Nov 5, 2021
A deterministic object hashing algorithm for Node.js

Deterministic-Object-Hash A deterministic object hashing algorithm for Node.js. The Problem Using JSON.stringify on two objects that are deeply equal

Zane Bauman 7 Nov 30, 2022
Non-interactive publicly verifiable distributed key generation and resharing algorithm over BLS12-381

NPVDKG-RS This repository contains a mathematical presentation and some code to demonstrate our developed non-interactive publicly verifiable distribu

NATRIX Official 8 May 19, 2022
🤖A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable

Tic-Tac-Toe AI A Tic-Tac-Toe solver that uses the minimax algorithm and alpha-beta pruning to make it unbeatable How it Works Tic-Tac-Toe is what is k

Martin 4 May 20, 2022
Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on the algorithm by Devillers & Guigue.

fast-triangle-triangle-intersection Fast and robust triangle-triangle intersection test with high precision for cross and coplanar triangles based on

Technology and knowledge for interaction 10 Nov 15, 2022
⭐️ my baekjoon algorithm

Baekjoon Algorithm Python3 import sys # 공백으로 구분된 2개 숫자 입력 받기 N, M = map(int, sys.stdin.readline().split()) # 여러 줄 입력 받기 n = int(sys.stdin.readline

InYoung Park 3 Jul 22, 2022
k-means algorithm module for n-dimensional data

K-Means Algorithm This module allows you to compute the k-Means algorithm with n-dimensional data. You simply put in your data as a list and the k you

null 3 Jan 31, 2022
A Flood-Fill Algorithm written in JavaScript

flood https://magnogen.net/flood A Flood-Fill Algorithm for Creative Coders This is the source code for a section of my website. You're welcome to sno

Magnogen 5 Dec 22, 2022
Deno's first lightweight, secure distributed lock manager utilizing the Redlock algorithm

Deno-Redlock Description This is an implementation of the Redlock algorithm in Deno. It is a secure, lightweight solution to control resource access i

OSLabs Beta 223 Dec 31, 2022
An algorithm for fast 2D pattern-matching with wildcards.

pattern-match-2d.js An algorithm for fast 2D pattern-matching with wildcards, with a demo app inspired by MarkovJunior (by Maxim Gumin). The algorithm

null 16 Nov 5, 2022