3 ms·
Hey, sure - here's 9 lines of code that implement a perceptron. I get ~95% of precision after a second with 400 samples. ```js const dotSign = (v1, v2) =
by inglor 10y ago
Hey, sure - here's 9 lines of code that implement a perceptron. I get ~95% of precision after a second with 400 samples.
```js
const dotSign = (v1, v2) => v1.reduce((prev, x, i) => prev + x * v2[i], 1) > 0 ? 1 : -1
module.exports = (data, weights = Array(data[0].content.length).fill(0)) => {
for(const {label, content} of data) {
const delta = (label - dotSign(content, weights)) / 2;
weights = weights.map((x, i) => x + delta * content[i]);
}
return { perceive: vector => dotSign(vector, weights), weights };
}
```
I can upload an electron app that does this with mnist if interested.
- anentropic 10y agohow long does does it take to get from 95% -> 98.8% though?
- attractivechaos 10y ago> I get ~95% of precision after a second with 400 samples. MNIST has 60k training samples and 10k test samples. Are you using only 400 of them? Is 95% the accuracy on the test samples or on the same set of training samples? I believe when we talk about MNIST accuracy, we always refer to the accuracy on the 10k test samples.
- quinnftw 10y agoIs this not a binary perceptron? How do you plan to classify all 10 digits with this?
- inglor 10y agoI cheated here (this _is_ a binary perceptron), but the conversion is super easy with one-vs-rest or one-vs-one (training all pairs and then doing pairwise comparison until we find the one that matches), that would still take ~20 seconds to train.