-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
I'm utilising the fromJSON
option of Brain JS to output my network to a json file and load it back in, however, I'm confused as to how I'm meant to train this...
Am I meant to run one set of data through the network in the .run([])
and then use that one json file for other data running through the data, or, am I meant to train it and keep appending data to the JSON file, either way, the following seems to return mostly the same result all of the time, I've stripped most of the training data, but the array of objects would be thousands of objects:
// require packages
const brain = require('brain.js')
const fs = require('fs');
const path = require('path');
const args = require('minimist')(process.argv.slice(2))
// check if we have a trained network already
const checkIfNetworkExists = fs.existsSync('./js/generate/data/trained-network.json')
// Loan & Term: init Training Pattern
const myNetwork = new brain.NeuralNetwork({hiddenLayers: [7, 7]})
if (!checkIfNetworkExists) {
const trainingData = [
{input:[451,2200,42,0,650,200,150],output:[0,1,1,0,0,1,1]},{input:[851,1400,52,150,500,50,850],output:[0,1,1,0,0,0,0]}
]
// train the network
if (args['enableAsyncTraining'] && args['enableAsyncTraining'] === 'true') {
myNetwork.trainAsync(trainingData, trainingOptions)
} else {
myNetwork.train(trainingData, trainingOptions)
}
// write trained network to file
fs.writeFileSync('./js/generate/data/trained-network.json', JSON.stringify(myNetwork.toJSON(), null, ' '));
} else {
// load network if it exists
myNetwork.fromJSON(JSON.parse(fs.readFileSync('./js/generate/data/trained-network.json', 'utf8')));
}
// run the network
myNetwork.run([100, 2000, 40, 6, 650, 200, 100])
Metadata
Metadata
Assignees
Labels
No labels