I want to send a very simple module variable from svm
(machine learning) to server app.js
, I'm working with NodeJS .
This is my code:
'use strict';
var so = require('stringify-object');
var svm = require('../lib');
var xor = [
[[0, 0], 0],
[[0, 1], 1],
[[1, 0], 1],
[[1, 1], 0] ];
// initialize predictor
var clf = new svm.CSVC({ kFold: 1 });
clf.train(xor)
.progress(function(progress){
console.log('training progress: %d%', Math.round(progress*100));
})
.spread(function (model, report) {
console.log('training report: %s\nPredictions:', so(report));
xor.forEach(function(ex){
var prediction = clf.predictSync(ex[0]);
console.log(' %d XOR %d => %d', ex[0][0], ex[0][1], prediction);
});
});
How to send variable prediction
?
I modified it like this:
'use strict';
var so = require('stringify-object');
var svm = require('../lib');
var xor = [
[[0, 0], 0],
[[0, 1], 1],
[[1, 0], 1],
[[1, 1], 0]
];
var prediction;
// initialize predictor
var clf = new svm.CSVC({
kFold: 1
});
clf.train(xor)
.progress(function(progress){
console.log('training progress: %d%', Math.round(progress*100));
})
.spread(function (model, report) {
console.log('training report: %s\nPredictions:', so(report));
xor.forEach(function(ex){
prediction = clf.predictSync(ex[0]);
console.log(' %d XOR %d => %d', ex[0][0], ex[0][1], prediction);
prediction="prediciendo desde cbba";
return {
prediction:1
};
});
});
exports.prediction =prediction;
But I can not show in app.js
. The variable reaches undefined
.
Code:
var ror = require('./node_modules/node-svm/examples/evaluation-example');
console.log(ror.prediction);