after training on iris data https://archive.ics.uci.edu/ml/datasets/Iris/ output of one iris is massively higher than the others
download the csv of data
const brain = require('brain.js');
const net = new brain.NeuralNetwork();
const fs = require('fs');
const data = fs.readFileSync('./iris.csv').toString();
const trainingData = data.split('\r\n').map((d) => {
const [slength, swidth, plength, pwidth, flower] = d.split(',');
return {
input: {
slength: slength / 10,
swidth: swidth / 10,
plength: plength / 10,
pwidth: pwidth / 10,
},
output: {
[flower]: 1,
},
};
});
const trainResults = net.train(trainingData);
console.log(trainResults);
const result = net.run({
slength: 0.51,
swidth: 0.35,
plength: 0.13999999999999999,
pwidth: 0.1 });
console.log(result);
3
{ 'Iris-setosa': 0.9973204731941223,
'Iris-versicolor': 0.003389077726751566,
'Iris-virginica': 2.462011443240403e-13 }
should be more like
{ 'Iris-setosa': 0.9973204731941223,
'Iris-versicolor': 0.003389077726751566,
'Iris-virginica': 0.003 }
training results
{ error: 0.008838672393814171, iterations: 20000 }
I think you missed e-13 in the result?
'Iris-virginica': 2.462011443240403e-13
The input I used in the .run is Iris-setosa and that came out as 0.99 almost perfect.
is there where the float is long i'm getting the notation rather than the number? if so is there anyway to get the network to just round so I don't get values like this?
Iris-virginica has a very low value, read it again, please. You have missed e13 in it. Your output is perfect.
Iris-virginica result is written in scientific notation.
Iris-virginicahas a very low value, read it again, please. You have missed e13 in it. Your output is perfect.
Thanks, I worked that out after I re-read your comment. I am guessing this is just a javascript thing with floats?
the result is actually
0.0000000000002462011443240403
It's exponent values. An effort to make it more computationally easy and/or visually friendly. 13 zeros vs 2 zeros. Happens to the best of us.
It's exponent values. An effort to make it more computationally easy and/or visually friendly. 13 zeros vs 2 zeros. Happens to the best of us.
is there an option to stop it from doing this and just return the float?
Sadly it is a core part of javascript, but it _is_ a float, and is really just for displaying purposes only. I wouldn't worry about it.
The other option you can go with is formatting the output as a string, such as using .toFixed(14).
Example:
2.462011443240403e-13.toFixed(14); // -> "0.00000000000025"
Most helpful comment
The other option you can go with is formatting the output as a string, such as using
.toFixed(14).Example: