UNPKG

neural-network-node

Version:

A simple neural network coded from scratch with no external modules. Lets you train your own neural network in a simple and easy to learn way.

26 lines (19 loc) 685 B
const NeuralNetwork = require("neural-network-node"); let nn = new NeuralNetwork.Standard(1, 2, 1); /*approximates the y = sinx function. After you train it, you should be able to input an x-value and get a y-value close to the output*/ function generatedata() { let input = Math.random() * 2 * Math.PI; let output = Math.sin(input); return { input: [input], output: [output], }; } for (let i = 0; i < 10000; i++) { var data = generatedata(); nn.train(data.input, data.output); } console.log("Finished training"); const output = nn.predict([Math.PI]); //The more you train the model, the closer this gets to zero console.log(output);