https://github.com/isair/tensorflow-load-csv
🤖 TensorFlow.js CSV loading on steroids. Clean up, normalise, transform, shuffle, and split your data all in a handful of lines and dive right into the fun parts of ML.
https://github.com/isair/tensorflow-load-csv
browser csv csv-files javascript machine-learning node tensorflow typescript
Last synced: 2 months ago
JSON representation
🤖 TensorFlow.js CSV loading on steroids. Clean up, normalise, transform, shuffle, and split your data all in a handful of lines and dive right into the fun parts of ML.
- Host: GitHub
- URL: https://github.com/isair/tensorflow-load-csv
- Owner: isair
- Created: 2020-08-02T21:44:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T01:22:29.000Z (about 3 years ago)
- Last Synced: 2025-09-07T20:23:07.141Z (7 months ago)
- Topics: browser, csv, csv-files, javascript, machine-learning, node, tensorflow, typescript
- Language: TypeScript
- Homepage:
- Size: 3.07 MB
- Stars: 44
- Watchers: 3
- Forks: 9
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tensorflow-load-csv
[](https://opensource.org/licenses/MIT)
[](http://www.typescriptlang.org/)
[](https://github.com/prettier/prettier)

A library that aims to remove the overhead of creating tensors from CSV files completely; allowing you to dive right into the fun parts of your ML project.
- [Lightweight](https://bundlephobia.com/result?p=tensorflow-load-csv).
- Fast.
- Flexible.
- TypeScript compatible.
- 100% test coverage.
## Documentation
You can find the docs [here](https://barissencan.com/tensorflow-load-csv/modules/loadcsv.html#default).
## Installation
NPM:
```sh
npm install tensorflow-load-csv
```
Yarn:
```sh
yarn add tensorflow-load-csv
```
## Usage
Simple usage:
```js
import loadCsv from 'tensorflow-load-csv';
const { features, labels } = loadCsv('./data.csv', {
featureColumns: ['lat', 'lng', 'height'],
labelColumns: ['temperature'],
});
features.print();
labels.print();
```
Advanced usage:
```js
import loadCsv from 'tensorflow-load-csv';
const { features, labels, testFeatures, testLabels } = loadCsv('./data.csv', {
featureColumns: ['lat', 'lng', 'height'],
labelColumns: ['temperature'],
mappings: {
height: (ft) => ft * 0.3048, // feet to meters
temperature: (f) => (f < 50 ? [1, 0] : [0, 1]), // cold or hot classification
}, // Map values based on which column they are in before they are loaded into tensors.
flatten: ['temperature'], // Flattens the array result of a mapping so that each member is a new column.
shuffle: true, // Pass true to shuffle with a fixed seed, or a string to use as a seed for the shuffling.
splitTest: true, // Splits your data in half. You can also provide a certain row count for the test data, or a percentage string (e.g. '10%').
standardise: ['height'], // Calculates mean and variance for each feature column using data only in features, then standardises the values in features and testFeatures. Does not touch labels.
prependOnes: true, // Prepends a column of 1s to your features and testFeatures tensors, useful for regression problems.
});
features.print();
labels.print();
testFeatures.print();
testLabels.print();
```