# tmcw/simple-statistics

### Subversion checkout URL

You can clone with HTTPS or Subversion.

Set up travis, add first test

commit 724af7d5ceca6e384315fb8f3d7a413cef279314 1 parent 4c876ac
authored
3  .travis.yml
 @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 0.6
 @@ -1,3 +1,5 @@ +[![Build Status](https://secure.travis-ci.org/tmcw/simple-statistics.png?branch=master)](http://travis-ci.org/tmcw/simple-statistics) + A project to learn about and make simple reference implementations of statistics algorithms.
3  index.js
 @@ -0,0 +1,3 @@ +module.exports = { + linear_regression: require('./src/linear_regression.js') +};
7 package.json
 @@ -8,8 +8,13 @@ "url": "git://github.com/tmcw/node-statistics.git" }, "dependencies": {}, - "devDependencies": {}, + "devDependencies": { + "mocha": "1.2.x" + }, "optionalDependencies": {}, + "scripts": { + "test": "mocha" + }, "engines": { "node": "*" }
2  src/linear_regression.js
 @@ -64,6 +64,8 @@ function linear_regression() { return linreg; } +if (module && module.exports) module.exports = linear_regression; + // This implementation was influenced by // // * [Least squares in Javascript](http://dracoblue.net/dev/linear-least-squares-in-javascript/159/)
8 test/linear_regression.test.js
 @@ -0,0 +1,8 @@ +var assert = require('assert'); +var ss = require('../index.js'); + +it('correctly generates a line for a 0, 0 to 1, 1 dataset', function() { + var l = ss.linear_regression().data([[0, 0], [1, 1]]); + assert.equal(l.line()(0), 0); + assert.equal(l.line()(1), 1); +});
19 tests/bayes.test.js
 @@ -1,19 +0,0 @@ -var weather = require('./weather.js'); -var bayesian = require('../bayesian.js'); - - -describe('weather is well formed', function() { - weather[0].observation.outlook.should.equal('sunny'); -}); - -describe('bayes', function() { - var b = bayesian(); - for (var i = 0; i < weather.length; i++) { - b.train(weather[i].observation, weather[i].category); - } - - describe('initial training should set overall stats', function() { - b.n_samples().should.equal(14); - b.categoryCount.yes.should.equal(9); - }); -});
16 tests/id3.test.js
 @@ -1,16 +0,0 @@ -var id3 = require('../id3'); - - -describe('id3', function() { - var dt = id3(); - var noentropy = [{ a: 1 }]; - describe('entropy is well-defined when there is none', function() { - dt.entropy(noentropy, 'a').should.equal(0); - }); - describe('entropy is well-defined when there is all', function() { - dt.entropy(noentropy, 'b').should.equal(0); - }); - describe('value gain', function() { - dt.gain(noentropy, 'b', 'c').should.equal(0); - }); -});
33 tests/weather.js
 @@ -1,33 +0,0 @@ -/* - * From Witten and Frank, 1999, p. 9 - * via - * http://www.csse.monash.edu.au/courseware/cse5230/2004/assets/naivebayesTute.pdf - */ - -module.exports = [ - 'sunny hot high false no', - 'sunny hot high true no', - 'overcast hot high false yes', - 'rainy mild high false yes', - 'rainy cool normal false yes', - 'rainy cool normal true no', - 'overcast cool normal true yes', - 'sunny mild high false no', - 'sunny cool normal false yes', - 'rainy mild normal false yes', - 'sunny mild normal true yes', - 'overcast mild high true yes', - 'overcast hot normal false yes', - 'rainy mild high true no' -].map(function(l) { - var x = l.split(' '); - return { - observation: { - outlook: x[0], - temperature: x[1], - humidity: x[2], - windy: x[3] - }, - category: x[4] - }; -});