MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / createDataset

Function createDataset

abalone-node/data.js:27–53  ·  view source on GitHub ↗

* Load a local csv file and prepare the data for training. Data source: * https://archive.ics.uci.edu/ml/datasets/Abalone * * @param {string} csvPath The path to csv file. * @returns {tf.data.Dataset} The loaded and prepared Dataset.

(csvPath)

Source from the content-addressed store, hash-verified

25 * @returns {tf.data.Dataset} The loaded and prepared Dataset.
26 */
27async function createDataset(csvPath) {
28 const dataset = tf.data.csv(
29 csvPath, {hasHeader: true, columnConfigs: {'rings': {isLabel: true}}});
30 const numOfColumns = (await dataset.columnNames()).length - 1;
31 // Convert features and labels.
32 return {
33 dataset: dataset.map(row => {
34 const rawFeatures = row['xs'];
35 const rawLabel = row['ys'];
36 const convertedFeatures = Object.keys(rawFeatures).map(key => {
37 switch (rawFeatures[key]) {
38 case 'F':
39 return 0;
40 case 'M':
41 return 1;
42 case 'I':
43 return 2;
44 default:
45 return Number(rawFeatures[key]);
46 }
47 });
48 const convertedLabel = [rawLabel['rings']];
49 return {xs: convertedFeatures, ys: convertedLabel};
50 }),
51 numOfColumns: numOfColumns
52 };
53}
54
55module.exports = createDataset;

Callers 2

data_test.jsFile · 0.85
runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected