Percipio
Easy Data science (Machine learning) in JavaScript & Node (Multi-armed bandits, Naive Bayes)
Install / Use
/learn @curiousily/PercipioREADME
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
- <em>Arm 1</em> - id: 1, reward: Java
- <em>Arm 2</em> - 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 git@github.com:naughtyspirit/percipio.git
cd percipio
npm install
Run tests
npm test
License
MIT
Related Skills
proje
Interactive vocabulary learning platform with smart flashcards and spaced repetition for effective language acquisition.
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
groundhog
400Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
