Giter VIP home page Giter VIP logo

online-stats's Introduction

Online statistical algorithms for browsers and Node.js

Collection of online algorithms for data exploration and analysis implemented in JavaScript. Online algorithms process inputs piece by piece. That means you can process data without storing it in memory. More about online algorithms: https://en.wikipedia.org/wiki/Online_algorithm

Most algorithms of online-stats also support more usual batch mode (i.e. mean([1,2,3,4]))

Installation

npm i -S online-stats

Usage

const Stats = require('online-stats') // { Mean, Median, Max, Min, ... }

To process data sequentially we need functions to have internal state. That's why there's one extra step - functions initialization

const mean = Stats.Mean() // -> function mean
const median = Stats.Median() // -> function median
...

When functions are initialized, just call them passing a value (for example: mean(x)). Result is returned. To get a final result just call a function without any params: const result = mean()

Web demo

Check how the online-stats package is used for online data profiling on StatSim Profile

Mean

const mean = Stats.Mean()

mean(1) // -> 1
mean(2) // -> 1.5
mean(9) // -> 4

console.log(mean()) // -> 4

Variance

const v = Stats.Variance({ddof: 1}) // 0 (default) - population variance, 1 - sample variance

v(1) // -> 0
v(2) // -> 0.5
v(9) // -> 19

console.log(v()) // -> 19

Median

const median = Stats.Median()

median(1) // -> 1
median(2) // -> 1.5
median(9) // -> 2

console.log(median()) // -> 2

Min

const min = Stats.Min()

min(2) // -> 2
min(6) // -> 2
min(1) // -> 1

console.log(min()) // -> 1

Max

const max = Stats.Max()

max(2) // -> 2
max(6) // -> 6
max(1) // -> 6

console.log(max()) // -> 6

Standard Deviation

const std = Stats.Std({ddof: 1}) // 0 (default) - population std, 1 - sample std (unbiased)

std(1) // -> 0
std(2) // ~> 0.7071
std(9) // ~> 4.3589

console.log(std()) // ~> 4.3589

Covariance

const a = [1, 3, 2, 5, 8, 7, 12, 2, 4]
const b = [8, 6, 9, 4, 3, 3, 2, 7, 7]
const cov = Stats.Covariance({ddof: 1})

a.forEach((ax, i) => { cov(ax, b[i]) })
console.log(cov()) // -> -8.069

Histogram

const hist = Stats.Histogram(20)

hist(2)
hist(6)
hist(1)

console.log(hist())

Autocovariance

const autocov = Stats.AutoCov(5)

;[1, 2, 3, 4, 5, 6, 7].forEach(v => { autocov(v) })

console.log(autocov())

Autocorrelation

const autocor = Stats.AutoCor(5)

;[1, 2, 3, 4, 5, 6, 7].forEach(v => { autocor(v) })

console.log(autocor())

Linear regression

const lr = Stats.LinReg()

const f = x => 0.5 * x + 2
;[1, 2, 3, 4, 5, 6].forEach(v => { lr(v, f(v)) })

console.log(lr([7])) // Predict

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.