1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
**This repo is under active development and is not production-ready. We are
actively developing as an open source project.**
TensorFlow.js Data provides simple APIs to load and parse data from disk or over
the web in a variety of formats, and to prepare that data for use in machine
learning models (e.g. via operations like filter, map, shuffle, and batch).
This project is the JavaScript analogue of
[tf.data](https://www.tensorflow.org/datasets) on the
Python/C++ side. TF.js Data will match the tf.data API to the extent possible.
To keep track of issues we use the [tensorflow/tfjs](https://github.com/tensorflow/tfjs/issues?q=is%3Aissue+is%3Aopen+label%3Acomp%3Adata) Github repo with `comp:data` tag.
There are two ways to import TensorFlow.js Data
1. 2.
Reading a CSV file
```js
import * as tf from '@tensorflow/tfjs';
const csvUrl = 'https://storage.googleapis.com/tfjs-examples/multivariate-linear-regression/data/boston-housing-train.csv';
async function run() {
// 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 = tf.data.csv(
// Number of features is the number of column names minus one for the label
// column.
const numOfFeatures = (await csvDataset.columnNames()).length - 1;
// Prepare the Dataset for training.
const flattenedDataset =
// Define the model.
const model = tf.sequential();
model.add(tf.layers.dense({
}));
model.compile({
});
// Fit the model using the prepared Dataset
return model.fitDataset(flattenedDataset, {
});
}
run().then(() => console.log('Done'));
```
- -