So I'm new to tensorflow.js and I have been trying to practice with an exercise. I have a json dataset and I want to show the val acc but all the example that I could find had .csv data sets. I would appreciate it if anyone could send me a link to such an example so I can better understand or to explain it here in the answers. Here is what I'm doing:
const trainingData = tf.tensor1d(horses.map(item =>
findAvg( filterOdds(item.prices))
))
const testingData = tf.tensor1d(horsesTesting.map(item =>
findAvg( filterOdds(item.prices))
));
const outputData = tf.tensor2d(horses.map(item => [
item.position === 1 ? 1 : 0,
item.position !== 1 ? 1 : 0,
// item.position != 1 ? 1 : 0,
]))
model.fit(trainingData, outputData, {epochs: 10})
.then((history) => {
// console.log(history)
model.predict(testingData).print()
})
Output: 4404ms 184us/step - acc=0.890 loss=0.0866 precision=0.00
what I found in the examples:
const trainingUrl1 = 'wdbc-train.csv';
// Take a look at the 'wdbc-train.csv' file and specify the column
// that should be treated as the label in the space below.
// HINT: Remember that you are trying to build a classifier that
// can predict from the data whether the diagnosis is malignant or benign.
const trainingData = tf.data.csv(trainingUrl1, {
columnConfigs: {
diagnosis: {
isLabel: true
}
}
});
const convertedTrainingData = // YOUR CODE HERE
trainingData.map(({xs, ys}) => {
return{ xs: Object.values(xs), ys: Object.values(ys)};
}).batch(10);
const testingUrl2 = 'wdbc-test.csv';
const testingData = tf.data.csv(testingUrl2, {
columnConfigs: {
diagnosis: {
isLabel: true
}
}
});
const convertedTestingData = // YOUR CODE HERE
testingData.map(({xs, ys}) => {
return{ xs: Object.values(xs), ys: Object.values(ys)};
}).batch(10);
await model.fitDataset(convertedTrainingData,
{epochs:35,
validationData: convertedTestingData,
callbacks:{
onEpochEnd: async(epoch, logs) =>{
console.info("Epoch: " + epoch + " Loss: " + logs.loss + " Accuracy: " + logs.acc + " val_acc " + logs.val_acc);
}
}});
Output:
Epoch: 1 Loss: 0.08664028346538544 Accuracy: 0.784 val_acc 0.919