hola buenas, quiero enviar una variable de un modulo muy sencillo de svm(machine learning) al servidor app.js, estoy trabajando con nodejs
este es mi codigo
'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);
});
});
como enviar la variable prediccion?
lo modifique asi
'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;
pero no logro mostrar en el app.js, la variable llega undefined
var ror = require('./node_modules/node-svm/examples/evaluation-example');console.log(ror.prediction);
ayuda porfavor
Prueba ésto:
'use strict';
var so = require('stringify-object');
var svm = require('../lib');
var exports = module.exports = {};
var xor = [
[[0, 0], 0],
[[0, 1], 1],
[[1, 0], 1],
[[1, 1], 0]
];
// inicializas prediction a -1
exports.prediction = -1;
// 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";
// exportas prediction calculada
exports.prediction = prediction;
});
});