Seemingly Random Predictions
ALEEF02 opened this issue · comments
Anthony Ford commented
I have the following code to make a net with 4 inputs, one hidden layer, and 4 outputs. When I try to pull a prediction from the data after training, the values are always wildly different on every reload. Am I doing something wrong?
var layer_defs = [];
layer_defs.push({type:'input', out_sx:1, out_sy:1, out_depth:4});
layer_defs.push({type:'fc', num_neurons:4, activation:'relu'});
layer_defs.push({type:'regression', num_neurons:4});
var net = new convnetjs.Net();
net.makeLayers(layer_defs);
var my_data = [{"pages":[11,7,8,8],"quizzes":[1,0,0,1]},{"pages":[5,11,9,7],"quizzes":[0,1,0,1]},{"pages":[9,4,3,5],"quizzes":[1,0,0,1]}];
var trainer = new convnetjs.Trainer(net, {method: 'adadelta', l2_decay: 0.001,
batch_size: 10});
for (var it = 0; it < 1000; it++) {
for (var i = 0; i < my_data.length; i++) {
var x = new convnetjs.Vol(1,1,4,0.0); // a 1x1x2 volume initialized to 0's.
x.w[0] = my_data[i].pages[0];
x.w[1] = my_data[i].pages[1];
x.w[2] = my_data[i].pages[2];
x.w[3] = my_data[i].pages[3];
var y = new convnetjs.Vol(1,1,4,0.0);
y.w[0] = my_data[i].quizzes[0];
y.w[1] = my_data[i].quizzes[1];
y.w[2] = my_data[i].quizzes[2];
y.w[3] = my_data[i].quizzes[3];
trainer.train(x, y);
}
}
var json = net.toJSON();
var str = JSON.stringify(json);
console.log("Net: " + str);
document.write("Net: " + str);
var testPages = [9,4,3,5];
var volPages = new convnetjs.Vol(1,1,4,0.0);
volPages.w[0] = testPages[0];
volPages.w[1] = testPages[1];
volPages.w[2] = testPages[2];
volPages.w[3] = testPages[3];
console.log(volPages);
var predicted_values = net.forward(volPages);
console.log("Prediction: " + predicted_values.w[0] + ", " + predicted_values.w[1] + ", " + predicted_values.w[2] + ", " + predicted_values.w[3]);
//should output something close to [1,0,0,1]
Noam Gaash commented
sounds like you're overfitting your dataset.
extrapolate new point may result different results, due the stochastic nature of neural networks.
Anthony Ford commented
I fixed the issue a couple weeks back. The issue was that the y
in trainer.train(x, y);
is not supposed to be a covnetjs.Vol
. It should just be put in as an array of output values.