I am trying to input an array of data and output a prediction or a guess for what the result should be for the given data, I do not know much about neural nets but have a basic understanding on how their training works... I was hoping that it would see the two given inputs combined add up to the output in the three examples I provided for it such as [1, 2] should = 3 but I have hit a wall with inputting arrays and am getting the fallowing error
UnhandledPromiseRejectionWarning: Error: input expected a batch of elements where each example has shape [1] (i.e.,tensor shape [*,1]) but the input received an input with 3 examples, each with shape [2] (tensor shape [3,2])
any ideas someone can give me on how I should be going about this would be etremely helpful -.-
import tf from '@tensorflow/tfjs';
// create model object
const model = tf.sequential();
model.add(tf.layers.dense({
units: 1,
inputShape: [1]
}));
// compile model object
model.compile({
optimizer: 'sgd',
loss: 'meanSquaredError'
});
// training datasets
// input data for training
const xs = tf.tensor2d([
[1, 2],
[5, 6],
[3, 4]
]);
// output data for training
const ys = tf.tensor1d([
3,
11,
7
]);
async function firstFunction(_callback) {
// Train model with fit().method
await model.fit(xs, ys, {
epochs: 100000
})
_callback();
}
function secondFunction() {
//We wait for the call back from first function.
firstFunction(function() {
// We run the prediction.
prediction = model.predict(tf.tensor2d([
[6, 9],
])).dataSync()[0]
});
}
secondFunction()