How to use the @tensorflow/tfjs-data.csv function in @tensorflow/tfjs-data

To help you get started, we’ve selected a few @tensorflow/tfjs-data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tensorflow / tfjs-data / tfjs-data / demo / boston-housing / data.ts View on Github external
private async prepareDataset(url: string) {
    // We want to predict the column "medv", which represents a median value of
    // a home (in $1000s), so we mark it as a label.
    const csvDataset = tfd.csv(url, {columnConfigs: {medv: {isLabel: true}}});

    // Reduces the object-type data to an array of numbers.
    const convertedDataset =
        csvDataset.map((row: Array<{[key: string]: number}>) => {
          const [rawFeatures, rawLabel] = row;
          const convertedFeatures = Object.values(rawFeatures);
          const convertedLabel = [rawLabel['medv']];
          return [convertedFeatures, convertedLabel];
        });
    return {
      dataset: convertedDataset.shuffle(100),
      numFeatures: (await csvDataset.columnNames()).length - 1
    };
  }
}

@tensorflow/tfjs-data

TensorFlow Data API in JavaScript

Apache-2.0
Latest version published 18 days ago

Package Health Score

92 / 100
Full package analysis