Running network from JSON seems inaccurate with hundreds of JSON objects?
See original GitHub issueI’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])
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
How to parse somewhat wrong JSON with Python?
I have tried simplejson and json-py and seems they could not be set up to parse such strings. I am running Python 2.5...
Read more >Working with JSON - Learn web development | MDN
In this article, we've given you a simple guide to using JSON in your programs, including how to create and parse JSON, and...
Read more >An Introduction to JSON | DigitalOcean
JSON, short for JavaScript Object Notation, is a format for sharing data. As its name suggests, JSON is derived from the JavaScript ...
Read more >Working With JSON Data in Python
In this tutorial you'll learn how to read and write JSON-encoded data using Python. You'll see hands-on examples of working with Python's built-in...
Read more >Resolve JSON errors in Amazon Athena
To find if there are invalid JSON rows or file names in the Athena table, do the following: 1. Create a table with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Normalize them to between 0 and 1 for the best results (NOTE: this isn’t a brain.js thing, it is just machine learning in general). Normalize the most negative number (or least number) to 0, and then the highest number to 1, everything else should be within that 0 to 1 range for effective normalization.
@sts-ryan-holton Can you please create a playground here, with your sample code: https://runkit.com/home
This will allow us to understand the code and we will be able to update code.