Decision tree JavaScript | Learn about Decision tree

Decision tree JavaScript | Learn about Decision tree
Techiio-author
Written by Sagar RabidasMarch 11, 2022
6 min read
JavaScript
8 VIEWS 2 LIKES 0 DISLIKES SHARE
2 LIKES 0 DISLIKES 8 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

Let's start the discussion with Decision tree JavaScript

Introduction to Decision tree javascript:-

Decision tree javascript is a tool that is utilized by software program builders to construct analytics tools that assist customers or clients to visualize decisions and to realize the effects of the results of that decision. Like other bushes in laptop technological know-how, the decision tree also has nodes. These nodes are named choice nodes and outcome nodes, final results nodes are also known as stop nodes. In sure situations, the choice tree additionally has risk nodes that prefer one institution of outcomes over other corporations of consequences under a few unique situations. The selection tree in javascript is a part of the diagram library on JavaScript.

Syntax of Decision Tree:-

var decisionTree =
new Case( true, Array(
new Case ( function(n){ return n < 0; }, Math.sin),
new Case ( function(n){ return n < 2; }, “0 <= n < 2” ),
new Case ( true, ‘Greater than two” )));
decisionTree.evaluate(1);
decisionTree.evaluate(-Math.PI/2);
decisionTree.evaluate(5);

Using this implementation, you can arbitrarily nest your tree:

Case.prototype = {
nomatch : { match : false },
match : function (v) { return  { match : true , result : v }; },
evaluate : function( object ) {
var match = this.predicate;
if ( match instanceof Function )
match = match( object );
if ( match ) {
if (this.action instanceof Function )
return this.match( this.action(object) );
if ( this.action instanceof Case )
return this.action.evaluate( object );
if ( this.action instanceof Array ) {
var decision;
var result;
for (var c = 0; c < this.action.length; c++ ) {
decision = this.action[c];
if ( decision instanceof Case ) {
result = decision.evaluate( object );
if (result.match)
return result;
} else throw("Array of Case expected");
}
return this.no match;
}
return this.match(this.action);
}
return this.no match;
}
};

Example of Decision Tree Javascript:-

// decision tree API
const decision = (conditionFunction, trueOutcome, falseOutcome) =>
(context) => conditionFunction(context) ? trueOutcome : falseOutcome;
const decide = (context, decision) => “{
const outcome  = decision (context);
return typeof outcome === “function” ? decide(context, outcome) : outcome;
}
// Example Code
const isPositive = x => x > 0;
const isNegative = x => x < 0;
const isZero = x => x === 0;
const numberSignDecision =
decision( isPositive, “+”, decision(isNegative, “-”, decision(isZero, “0”, ?)));
const contextValues = [“number”, 1, 0, -1, Number.NaN, ];
for (const value of contextValues) {
console.log(value, decide(value, numberSignDecision));
}

Advantages of Decision Tree:-

  • Decision Trees are easily understandable even by non-technical people and also easily interpretable.
  • Decision Trees can work efficiently even with little data and as well as Big Data.
  • Decision Trees use the model of the white box which means if a given result is provided by a model the explanation for the result is easily replicated by simple mathematics formulae.
  • It can be solved by combining with other decision techniques such as brainstorming and other techniques.

Disadvantages of Decision Tree:-

  • Most of the algorithms like ID3 and C4.5 require that the target attribute will have only discrete values.
  • As decision trees use the “divide and conquer” method, they tend to perform well if a few highly relevant attributes exist, but less so if many complex interactions are present.
  • The greedy characteristic of decision trees leads to another disadvantage that should be pointed out. This is its over-sensitivity to the training set, irrelevant attributes, and noise.

JavaScript
Java
Decision tree JS
JS
HTML
8 VIEWS 2 LIKES 0 DISLIKES SHARE
2 LIKES 0 DISLIKES 8 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance