Skip to content

Instantly share code, notes, and snippets.

@tomsoderlund
Last active September 21, 2023 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tomsoderlund/437c0c9c9aa268bae13314a4e887c788 to your computer and use it in GitHub Desktop.
Save tomsoderlund/437c0c9c9aa268bae13314a4e887c788 to your computer and use it in GitHub Desktop.
Basic prediction using neural networks (Synaptic.js)
/*
Adapted from Lian Li’s (@chimney42) example:
https://slidr.io/Chimney42/machine-learning-with-synaptic
https://www.youtube.com/watch?v=M5glN6XjDv8
You need to include synaptic.js - visit https://caza.la/synaptic/
See my own tests at https://codepen.io/tomsoderlund/pen/MvLZLW
*/
// 1. Learn
var learningDataSet = [
{ input: [43.2, 54.2], output: [1, 0, 0] },
];
var network = new Architect.Perceptron(learningDataSet[0].input.length, 6, 6, learningDataSet[0].output.length);
var trainer = new Trainer(network);
trainer.train(learningDataSet, { rate: 0.0003, iterations: 100 });
// 2. Predict
var predictionDataSet = { input: [32.42, 634.4] };
predictionDataSet.output = network.activate(predictionDataSet.input);
console.log(predictionDataSet);
@tomsoderlund
Copy link
Author

See my own Synaptic.js test at https://codepen.io/tomsoderlund/pen/MvLZLW

ai_test_balls_v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment