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

percipio

v0.1.2

Published

Easy Data science (Machine learning) in JavaScript & Node (Including Bandits & Naive Bayes)

Downloads

7

Readme

Percipio - Easy Data Science (Machine Learning) in JavaScript & Node

Percipio is a simple minimalistic JavaScript library for understanding & making decisions with data.

Features

  • Bayesian Bandit algorithm (using Thompson sampling)
  • Naive Bayes classifier

Install

npm install percipio

Quick Start

Let's find out which programming language is better! Java or C#, anyone? (this might be a bit contrived example...) We can model this using simple Multi-armed bandit experiment (Multi-armed bandit experiments are even used by Google)

Experiment setup

We define 2 arms (possible outcomes) as follows

  • Arm 1 - id: 1, reward: Java
  • Arm 2 - id: 2, reward: C#

and create the Bandit predictor

var bandits = require('percipio').bandits
var BanditPredictor = bandits.Predictor

var rewards = ["Java", "C#"]
var armIds = [0, 1]

var predictor = BanditPredictor([
    bandits.createArm(armIds[0], rewards[0]),
    bandits.createArm(armIds[1], rewards[1])
])

Hidden probabilities

Next let's choose the probabilities which the predictor should find

var hiddenProbabilities = [0.5, 0.7] 

Simulation

Let's define our result simulation function (in the real world you should get results from your app, users etc.)

function simulateResult(p){
    return Math.random() < p ? 1 : 0
}

And run the simulation

for (var i = 0; i < 1000; i++) {
    var arm = predictor.predict() 
    var p = hiddenProbabilities[arm.id]
    predictor.learn(arm, simulateResult(p))
}

Result

Now the predictor has (hopefully) learned the hidden probabilities and we can get them

var javaProbabilities = predictor.posteriorProbabilities()[0]
var cSharpProbabilities = predictor.posteriorProbabilities()[1]
console.log(javaProbabilities)
console.log(cSharpProbabilities)

Complete example

Now try to run this yourself

var bandits = require('percipio').bandits
var BanditPredictor = bandits.Predictor

var rewards = ["Java", "C#"]
var armIds = [0, 1]

var predictor = BanditPredictor([
    bandits.createArm(armIds[0], rewards[0]),
    bandits.createArm(armIds[1], rewards[1])
])

var hiddenProbabilities = [0.5, 0.7]

function simulateResult(p){
    return Math.random() < p ? 1 : 0
}

for (var i = 0; i < 1000; i++) {
    var arm = predictor.predict() 
    var p = hiddenProbabilities[arm.id]
    predictor.learn(arm, simulateResult(p))
}

var javaProbabilities = predictor.posteriorProbabilities()[0]
var cSharpProbabilities = predictor.posteriorProbabilities()[1]
console.log(javaProbabilities)
console.log(cSharpProbabilities)

Current state

Pretty alphaish, I guess. Looking forward to implement

  • kNN
  • Linear regression
  • Data loaders/importers

Wanna help out?

Hop right in!

Development setup

git clone [email protected]:naughtyspirit/percipio.git
cd percipio
npm install

Run tests

npm test

License

MIT