-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnn.js
More file actions
32 lines (29 loc) · 823 Bytes
/
nn.js
File metadata and controls
32 lines (29 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var synaptic = require('synaptic');
var network = new synaptic.Architect.Perceptron(4,6,6);
var parse = require('csv-parse');
var fs = require('fs');
var trainer = new synaptic.Trainer(network);
var ds = [];
var parser = parse({delimiter: ','});
// Use the writable stream api
parser.on('readable', function(){
while(record = parser.read()){
ds.push({input:[row[0]/18000,row[1],row[2],row[3]]/1.41,output:[row[4],row[5]/3,row[6]/3,row[7]/5,row[8]/20000,row[9]/2]});
}
});
parser.on('error', function(err){
console.log(err.message);
});
parser.on('finish', function(){
trainer.train(ds);
console.log(network.toJSON());
});
fs.readFile('example_data.csv', function (err, data) {
data = data.toString();
if (err) throw err;
var d = data.split("\n");
for(r of d){
parser.write(d);
}
});
parser.end();