npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pmml2js

v1.0.0

Published

Conversion of PMML to JavaScript Code

Downloads

2

Readme

PMML to Javascript (pmml2js)

This projects aims on allowing PMML to JavaScript Code transformation so that you can run it in your browser.

Currently supported are:

  • Decision Trees
  • Random Forests (comming soon)
  • Baysian Classifiers (comming soon)

Decision Trees

The decision tree engine was created by artistoex.

Code Attribution

  • Author: artistoex
  • Source: http://stackoverflow.com/questions/8368698/how-to-implement-a-decision-tree-in-javascript-looking-for-a-better-solution-th/8369235#8369235
  • Date: Dec 3 '11 at 16:50
  • SO License: CC-Wiki
  • No other License Mentioned (Checked on Dec. 11 2015)

Notes (Andrei Miclaus):

  • Depth First Search through the tree.
  • Supports non-binary decision trees.

Decision Tree Usage Examples

All examples are available as QUnit tests.

Example 1: Creating a decision tree for binary sorting

/**
Tree (Sort):
              5
     3                 8
<3       >3       <8       >8

**/
QUnit.test("binary search tree as decision tree test", function(assert){
    var decisionTree = 
        new Case( true, Array(
                      new Case ( function(n){ return n < 5; },  Array(
                                                              new Case ( function(n){ return n < 3; }, "<3"),
                                                              new Case ( function(n){ return n > 3; }, ">3" )
                                                              )),
                      new Case ( function(n){ return n > 5; }, Array(
                                                              new Case ( function(n){ return n < 8; }, "<8"),
                                                              new Case ( function(n){ return n > 8; }, ">8" )
                                                              ))
                      ));

    assert.ok(decisionTree.evaluate(1).result == "<3", "Passed <3!");
    assert.ok(decisionTree.evaluate(10).result == ">8", "Passed >8!");
})

Example 2: Creating a decision tree for the Iris Dataset

/**
Tree (Sort):
           Petal.Length < 2.45
		  /                  \ 
     "setosa"		Petal.Width >= 2.45         
					/				  \
              "versicolor"        "virginica"

**/
QUnit.test("binary search tree as decision tree test", function(assert){
    var decisionTree = 
        new Case( true, Array(
                      new Case ( function(observation){ return observation.Petal_Length < 2.45; },  "setosa" ),
                      new Case ( function(observation){ return observation.Petal_Length >= 2.45; }, Array(
                                                              new Case ( function(observation){ return observation.Petal_Width < 1.75 }, "versicolor"),
                                                              new Case ( function(observation){ return observation.Petal_Width >= 1.75 }, "virginica" )
                                                              ))
                      ));

	dataset = new Array()
	// setosa test object
	dataset[0] = {
        Petal_Length : "2",
        Petal_Width : "3",
        Sepal_Length : "5",
		Sepal_Width : "13"
	}
	
	// versicolor test object
	dataset[1] = {
        Petal_Length : "3",
        Petal_Width : "1.5",
        Sepal_Length : "5",
		Sepal_Width : "13"
	}

	// virginica test object
	dataset[2] = {
        Petal_Length : "2.45",
        Petal_Width : "1.75",
        Sepal_Length : "5",
		Sepal_Width : "13"
	}

	
    assert.ok(decisionTree.evaluate(dataset[0]).result == "setosa", "Correctly classified as setosa!");
	assert.ok(decisionTree.evaluate(dataset[1]).result == "versicolor", "Correctly classified as versicolor!");
	assert.ok(decisionTree.evaluate(dataset[2]).result == "virginica", "Correctly classified as virginica!");
})

Using the API for Generating Executable Models

To use the examples, you need resolvable URLs to xml and xsl files. You can get and run the server used in the example below (including xml and xsl example files) from here Analytics Host.

Example 1: Requesting a decision tree for the Iris Dataset
var decisionTree;
//define the callback function used to evaluate the model
function evaluate(generatedDecisionTree){
  //initialise your variable with the value of the generated model
  decisionTree = generatedDecisionTree;

  //test methods
  assert.ok(decisionTree.evaluate(dataset[0]).result == "setosa", "Correctly classified as setosa!");
  assert.ok(decisionTree.evaluate(dataset[1]).result == "versicolor", "Correctly classified as versicolor!");
  assert.ok(decisionTree.evaluate(dataset[2]).result == "virginica", "Correctly classified as virginica!");

  //qunit helper for asynchronous tasks
  done();
}

initiateExecutableModel("http://localhost:3000/models/test_rpart.xml", "http://localhost:3000/pmml2js_decision_tree.xsl", evaluate);

Running the Tests

To run the tests open ./pmml2js/tests/*.html in the browser of your choice.