function convertToTensors(data, targets, testSplit) {
  const numExamples = data.length;
  if (numExamples !== targets.length) {
    throw new Error('data and split have different numbers of examples');
  }

  // Randomly shuffle `data` and `targets`.
  const indices = [];
  for (let i = 0; i < numExamples; ++i) {
    indices.push(i);
  }
  tf.util.shuffle(indices);

  const shuffledData = [];
  const shuffledTargets = [];
  for (let i = 0; i < numExamples; ++i) {
    shuffledData.push(data[indices[i]]);
    shuffledTargets.push(targets[indices[i]]);
  }

  // Split the data into a training set and a tet set, based on `testSplit`.
  const numTestExamples = Math.round(numExamples * testSplit);
  const numTrainExamples = numExamples - numTestExamples;

  const xDims = shuffledData[0].length;

  // Create a 2D `tf.Tensor` to hold the feature data.
  const xs = tf.tensor2d(shuffledData, [numExamples, xDims]);

  // Create a 1D `tf.Tensor` to hold the labels, and convert the number label
  // from the set {0, 1, 2} into one-hot encoding (.e.g., 0 --> [1, 0, 0]).
  const ys = tf.oneHot(tf.tensor1d(shuffledTargets).toInt(), IRIS_NUM_CLASSES);

  // Split the data into training and test sets, using `slice`.
  const xTrain = xs.slice([0, 0], [numTrainExamples, xDims]);
  const xTest = xs.slice([numTrainExamples, 0], [numTestExamples, xDims]);
  const yTrain = ys.slice([0, 0], [numTrainExamples, IRIS_NUM_CLASSES]);
  const yTest = ys.slice([0, 0], [numTestExamples, IRIS_NUM_CLASSES]);
  return [xTrain, yTrain, xTest, yTest];
}
Convert Iris data arrays to `tf.Tensor`s.

@param data The Iris input feature data, an `Array` of `Array`s, each element
  of which is assumed to be a length-4 `Array` (for petal length, petal
  width, sepal length, sepal width).
@param targets An `Array` of numbers, with values from the set {0, 1, 2}:
  representing the true category of the Iris flower. Assumed to have the same
  array length as `data`.
@param testSplit Fraction of the data at the end to split as test data: a
  number between 0 and 1.
@return A length-4 `Array`, with
  - training data as `tf.Tensor` of shape [numTrainExapmles, 4].
  - training one-hot labels as a `tf.Tensor` of shape [numTrainExamples, 3]
  - test data as `tf.Tensor` of shape [numTestExamples, 4].
  - test one-hot labels as a `tf.Tensor` of shape [numTestExamples, 3]