Deep Learning with Javascript 2. Exercises

Posted on April 3, 2020

Exercises from chapter two of Deep Learning with Javascript

  1. Substitute data from the example here to fit a model…

    https://codepen.io/tfjs-book/pen/JmerMM

    ////
    // Data
    ////
    function shuffle(data, target) {
      let counter = data.length
      let temp = 0
      let index = 0
      while (counter > 0) {
        index = (Math.random() * counter) | 0
        counter--
    
        temp = data[counter]
        data[counter] = data[index]
        data[index] = temp
    
        temp = target[counter]
        target[counter] = target[index]
        target[index] = temp
      }
    }
    let trainFeatures = [
      407,
      413,
      420,
      438,
      440,
      441,
      442,
      444,
      449,
      450,
      329,
      348,
      356,
      359,
      363,
      376,
      394,
      401,
      403,
      404,
    ]
    let trainTarget = [
      11,
      12,
      13,
      14,
      15,
      16,
      17,
      18,
      19,
      20,
      -5,
      -4,
      -3,
      -2,
      -1,
      5,
      6,
      7,
      8,
      9,
    ]
    let testFeatures = [
      184,
      236,
      242,
      243,
      254,
      255,
      261,
      270,
      315,
      326,
      451,
      452,
      458,
      463,
      467,
      488,
      491,
      492,
      497,
      499,
    ]
    let testTarget = [
      -19,
      -18,
      -17,
      -16,
      -15,
      0,
      -1,
      -2,
      -3,
      -4,
      21,
      22,
      23,
      24,
      25,
      26,
      27,
      28,
      29,
      30,
    ]
    
    const trainShuffled = shuffle(trainFeatures, trainTarget)
    const testShuffled = shuffle(testFeatures, testTarget)
    const trainData = {
      sizeMB: trainFeatures,
      timeSec: trainTarget,
    }
    const testData = {
      sizeMB: testFeatures,
      timeSec: testTarget,
    }

    https://codepen.io/jamescarl/pen/YzXoXGx