GithubHelp home page GithubHelp logo

bhanditz / tfjs-data Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tensorflow/tfjs-data

0.0 2.0 0.0 7.54 MB

Simple APIs to load and prepare data for use in machine learning models

Home Page: https://js.tensorflow.org

License: Apache License 2.0

JavaScript 3.06% Shell 1.34% TypeScript 95.60%

tfjs-data's Introduction

TensorFlow.js Data

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 on the Python/C++ side. TF.js Data will match the tf.data API to the extent possible.

Importing

There are two ways to import TensorFlow.js Data

  1. You can access TensorFlow.js Data through the union package: @tensorflow/tfjs
  2. You can get TensorFlow.js Data as a module: @tensorflow/tfjs-data. Note that tfjs-data has peer dependency on tfjs-core, so if you import @tensorflow/tfjs-data, you also need to import @tensorflow/tfjs-core.

Sample Usage

Reading a CSV file

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(
    csvUrl, {
      columnConfigs: {
        medv: {
          isLabel: true
        }
      }
    });
  // 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 =
    csvDataset
    .map(([rawFeatures, rawLabel]) =>
      // Convert rows from object form (keyed by column name) to array form.
      [Object.values(rawFeatures), Object.values(rawLabel)])
    .batch(10);

  // Define the model.
  const model = tf.sequential();
  model.add(tf.layers.dense({
    inputShape: [numOfFeatures],
    units: 1
  }));
  model.compile({
    optimizer: tf.train.sgd(0.000001),
    loss: 'meanSquaredError'
  });

  // Fit the model using the prepared Dataset
  return model.fitDataset(flattenedDataset, {
    epochs: 10,
    callbacks: {
      onEpochEnd: async (epoch, logs) => {
        console.log(epoch, logs.loss);
      }
    }
  });
}

run().then(() => console.log('Done'));

For more information

tfjs-data's People

Contributors

davidsoergel avatar dsmilkov avatar tafsiri avatar caisq avatar bileschi avatar reighlan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.