question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running network from JSON seems inaccurate with hundreds of JSON objects?

See original GitHub issue

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])

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
robertleeplummerjrcommented, Dec 12, 2019

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.

2reactions
mubaidrcommented, Dec 27, 2019

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found