简体   繁体   English

获得不需要的brain.js输出

[英]getting unwanted brain.js output

I am trying to learn brain.js. 我正在努力学习brain.js。 I have written a code to input a text and get a number as an output. 我编写了一个代码来输入文本并将数字作为输出。 but I always get NaN as output. 但我总是把NaN作为输出。

var brain = require('brain.js')
var net = new brain.NeuralNetwork();

net.train([
  {input: "", output:[0]},
  {input: "Jack", output:[1]},
  {input: "Tim", output: [0]},
  {input: "James", output: [0]},
  {input: "JOHN", output: [0]},
  {input: "cathy", output: [0]},
  {input: "Boom", output: [0]},
]);

console.log("Jack = "+net.run("Jack"));
console.log("JOHN = "+net.run("JOHN"));
console.log("cathy = "+net.run("cathy"));

Your output is fine, but you are using an incompatible means of training brain.NeuralNetwork with input tokens (strings). 你的输出没问题,但你正在使用一种不相容的方法训练brain.NeuralNetwork与输入令牌(字符串)。 You need to feed in numbers somehow. 你需要以某种方式提供数字。 A way to do this is with objects who's properties are numbers. 一种方法是使用属性为数字的对象。 This will work: 这将有效:

var brain = require('brain.js')
var net = new brain.NeuralNetwork();

net.train([
  {input: { "": 1 }, output:[0]},
  {input: { "Jack": 1 }, output:[1]},
  {input: { "Tim": 1 }, output: [0]},
  {input: { "James": 1 }, output: [0]},
  {input: { "JOHN": 1 }, output: [0]},
  {input: { "cathy": 1 }, output: [0]},
  {input: { "Boom": 1 }, output: [0]},
]);

console.log("Jack = "+net.run({ "Jack": 1 }));
console.log("JOHN = "+net.run({ "JOHN": 1 }));
console.log("cathy = "+net.run({ "cathy": 1 }));

Working example: https://jsfiddle.net/robertleeplummerjr/xz06ghfp/3/ 工作示例: https//jsfiddle.net/robertleeplummerjr/xz06ghfp/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM