0

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
yudhiesh
  • 6,383
  • 3
  • 16
  • 49
Spectre
  • 47
  • 8
  • I am not sure I understood the question. You are already displaying the accuracy, aren't you ? – edkeveked Feb 09 '21 at 08:34
  • I noticed that there's a difference between accuracy and validation accuracy. What is the difference between them and how can I display validation accuracy in my code when using json data instead of .csv? – Spectre Feb 10 '21 at 00:08

1 Answers1

0

There are two options for loading the dataset already discussed in this answer:

  • convert json to csv and then use the csvDataSet loader

  • create a custom loader using json. The csvDataSet loader here can help started

Regarding acc and val_acc, the first is for the training data and the second for the testing data

edkeveked
  • 17,989
  • 10
  • 55
  • 93