January 2018
Intermediate to advanced
332 pages
7h 36m
English
Now that our tree is ready and returned, we can use this in our app.component to determine whether the prediction matches that of the expected outcome using the predict() method:
public predict(tree, input) { var node = tree; // loop over the entire tree while(!node[0].leaf){ // take node name e.g. creditScore var name = node[0].name; // take value from input sample var inputValue = input[name]; // check if branches for given input exist var childNode = filter(node[0].branches, ['name', inputValue]); // if branches exist return branches or default to No node = childNode.length ? childNode[0].branches : [{ leaf: true, value: 'No'}]; } // return final leaf value return node[0].value;}
Then, in the app.component ...
Read now
Unlock full access