Guys please help!
Why is this code not working?
const tf = require('/root/node_modules/@tensorflow/tfjs');
// define the training data
const data = [
{
Open: 10.0,
High: 15.3,
Low: 8.5,
Close: 11.7
},
{
Open: 11.2,
High: 13.2,
Low: 9.1,
Close: 12.4
}
];
// define the model
const model = tf.sequential();
model.add(tf.layers.dense({
units: 4,
inputShape: [4],
activation: 'sigmoid'
}));
model.add(tf.layers.dense({
units: 1,
activation: 'linear'
}));
model.compile({
optimizer: 'sgd',
loss: 'meanSquaredError'
});
// prepare the data for training
const inputs = data.map(d => [d.Open, d.High, d.Low, d.Close]);
const labels = data.map(d => d.Close);
const xs = tf.tensor2d(inputs);
const ys = tf.tensor2d(labels);
// train the model
model.fit(xs, ys, {
epochs: 500
}).then(() => {
// use the model to make predictions
const prediction = model.predict(tf.tensor2d([[11.5, 12.3, 9.5, 10.6]]));
console.log(prediction.dataSync()[0]);
});
I am getting this kind of error…
/root/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:18585
throw new Error('tensor2d() requires shape to be provided when `values` ' +
^
Error: tensor2d() requires shape to be provided when `values` are a flat/TypedArray