Giter Site home page Giter Site logo

adammendoza / simple-statistics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simple-statistics/simple-statistics

0.0 1.0 0.0 1.19 MB

simple statistics for javascript in node and the browser

Home Page: http://macwright.org/2012/06/26/simple-statistics.html

License: BSD 3-Clause "New" or "Revised" License

simple-statistics's Introduction

Build Status

A project to learn about and make simple reference implementations of statistics algorithms.

This code is designed to work in browsers (including IE) as well as in node.js.

Basic Descriptive Statistics

// Require simple statistics
var ss = require('simple-statistics');

// The input is a simple array
var list = [1, 2, 3];

// Many different descriptive statistics are supported
var sum = ss.sum(list),
    mean = ss.mean(list),
    min = ss.min(list),
    geometric_mean = ss.geometric_mean(list),
    max = ss.max(list),
    quantile = ss.quantile(0.25);

Linear Regression

// For a linear regression, it's a two-dimensional array
var data = [ [1, 2], [2, 3] ];

// simple-statistics can produce a linear regression and return
// a friendly javascript function for the line.
var line = ss.linear_regression()
    .data(data)
    .line();

// get a point along the line function
line(0);

var line = ss.linear_regression()

// Get the r-squared value of the line estimation
ss.r_squared(data, line);

Mixin Style

This is optional and not used by default. You can opt-in to mixins with ss.mixin().

This mixes simple-statistics methods into the Array prototype - note that extending native objects is a tricky move.

This will only work if defineProperty is available, which means modern browsers and nodejs - on IE8 and below, calling ss.mixin() will throw an exception.

// mixin to Array class
ss.mixin();

// The input is a simple array
var list = [1, 2, 3];

// The same descriptive techniques as above, but in a simpler style
var sum = list.sum(),
    mean = list.mean(),
    min = list.min(),
    max = list.max(),
    quantile = list.quantile(0.25);

Bayesian Classifier

var bayes = ss.bayesian();
bayes.train({ species: 'Cat' }, 'animal');
bayes.score({ species: 'Cat' });
// { animal: 1 }

Examples

Usage

To use it in browsers, grab simple_statistics.js. To use it in node, install it with npm or add it to your package.json.

npm install simple-statistics

To use it with component,

component install tmcw/simple-statistics

Contributors

See Also

  • stream-statistics, a sister project that implements many of the same measures for streaming data - as online algorithms

Javascript

Python

Their Own Language

simple-statistics's People

Contributors

tmcw avatar mattsacks avatar jthomm avatar

Watchers

Adam J. Mendoza avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.