Coder Social home page Coder Social logo

repetere / jsonstack-model Goto Github PK

View Code? Open in Web Editor NEW
5.0 4.0 1.0 13.28 MB

Deep Learning Classification, LSTM Time Series, Regression and Multi-Layered Perceptrons with Tensorflow

Home Page: https://repetere.github.io/jsonstack-model/

License: MIT License

TypeScript 88.42% HTML 11.56% Shell 0.03%
tensorflow deep-learning machine-learning ai multivariate-linear-regression classification-model nlp-machine-learning

jsonstack-model's Introduction

@jsonstack/Model - Machine Learning and Neural Networks with Tensorflow

Coverage Status Build, Test & Coverage

Getting started

Clone the repo and drop your module in the src directory.

# Install Prerequisites
$ npm install rollup typedoc jest sitedown --g

Basic Usage

$ npm run build #builds type declarations, created bundled artifacts with rollup and generates documenation

Introduction

This library is a compilation of model building modules with a consistent API for quickly implementing Tensorflow at edge(browser) or any JavaScript environment (Node JS / GPU).

Read the manual

List of Tensorflow models

Classification

Regression

Artificial neural networks (ANN)

LSTM Time Series

Basic Usage

TensorScript is and ECMA Script module designed to be used in an ES2015+ environment, if you need compiled modules for older versions of node use the compiled modules in the bundle folder.

Please read more on tensorflow configuration options, specifying epochs, and using custom layers in configuration.

Regression Examples

import * as tf from '@tensorflow/tfjs-node';
import { MultipleLinearRegression, DeepLearningRegression, setBackend } from '@jsonstack/model';
import ms from 'modelscript';

//setup jsonstack model tensorflow
setBackend(tf);

async function main(){
  const independentVariables = [ 'sqft', 'bedrooms',];
  const dependentVariables = [ 'price', ];
  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/portland_housing_data.csv');
  const DataSet = new ms.DataSet(housingdataCSV);
  const x_matrix = DataSet.columnMatrix(independentVariables);
  const y_matrix = DataSet.columnMatrix(dependentVariables);
  const MLR = new MultipleLinearRegression();
  await MLR.train(x_matrix, y_matrix);
  const DLR = new DeepLearningRegression();
  await DLR.train(x_matrix, y_matrix);
  //1600 sqft, 3 bedrooms
  await MLR.predict([1650,3]); //=>[293081.46]
  await DLR.predict([1650,3]); //=>[293081.46]
}
main();

Classification Examples

import * as tf from '@tensorflow/tfjs';
import { DeepLearningClassification, setBackend } from '@jsonstack/model';
import ms from 'modelscript';

//setup jsonstack model tensorflow
setBackend(tf);

async function main(){
  const independentVariables = [
    'sepal_length_cm',
    'sepal_width_cm',
    'petal_length_cm',
    'petal_width_cm',
  ];
  const dependentVariables = [
    'plant_Iris-setosa',
    'plant_Iris-versicolor',
    'plant_Iris-virginica',
  ];
  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/iris_data.csv');
  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {plant:'onehot'}, });
  const x_matrix = DataSet.columnMatrix(independentVariables);
  const y_matrix = DataSet.columnMatrix(dependentVariables);
  const nnClassification = new DeepLearningClassification();
  await nnClassification.train(x_matrix, y_matrix);
  const input_x = [
    [5.1, 3.5, 1.4, 0.2, ],
    [6.3, 3.3, 6.0, 2.5, ],
    [5.6, 3.0, 4.5, 1.5, ],
    [5.0, 3.2, 1.2, 0.2, ],
    [4.5, 2.3, 1.3, 0.3, ],
  ];
  const predictions = await nnClassification.predict(input_x); 
  const answers = await nnClassification.predict(input_x, { probability:false, });
  /*
    predictions = [
      [ 0.989512026309967, 0.010471616871654987, 0.00001649192017794121, ],
      [ 0.0000016141033256644732, 0.054614484310150146, 0.9453839063644409, ],
      [ 0.001930746017023921, 0.6456733345985413, 0.3523959517478943, ],
      [ 0.9875779747962952, 0.01239941269159317, 0.00002274810685776174, ],
      [ 0.9545140862464905, 0.04520365223288536, 0.0002823179238475859, ],
    ];
    answers = [
      [ 1, 0, 0, ], //setosa
      [ 0, 0, 1, ], //virginica
      [ 0, 1, 0, ], //versicolor
      [ 1, 0, 0, ], //setosa
      [ 1, 0, 0, ], //setosa
    ];
   */
}
main();
import * as tf from '@tensorflow/tfjs';
import { LogisticRegression, setBackend } from '@jsonstack/model';
import ms from 'modelscript';

//setup jsonstack model tensorflow
setBackend(tf);

async function main(){
  const independentVariables = [
    'Age',
    'EstimatedSalary',
  ];
  const dependentVariables = [
    'Purchased',
  ];
  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/social_network_ads.csv');
  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {Age:['scale','standard'],
  EstimatedSalary:['scale','standard'],}, });
  const x_matrix = DataSet.columnMatrix(independentVariables);
  const y_matrix = DataSet.columnMatrix(dependentVariables);
  const LR = new LogisticRegression();
  await LR.train(x_matrix, y_matrix);
  const input_x = [
    [-0.062482849427819266, 0.30083326827486173,], //0
    [0.7960601198093905, -1.1069168538010206,], //1
    [0.7960601198093905, 0.12486450301537644,], //0
    [0.4144854668150751, -0.49102617539282206,], //0
    [0.3190918035664962, 0.5061301610775946,], //1
  ];
  const predictions = await LR.predict(input_x); // => [ [ 0 ], [ 0 ], [ 1 ], [ 0 ], [ 1 ] ];
}
main();

Time Series Example

import * as tf from '@tensorflow/tfjs';
import { LSTMTimeSeries, setBackend } from '@jsonstack/model';
import ms from 'modelscript';

//setup jsonstack model tensorflow
setBackend(tf);

async function main(){
  const dependentVariables = [
    'Passengers',
  ];
  const airlineCSV = await ms.csv.loadCSV('./test/mock/data/airline-sales.csv');
  const DataSet = new ms.DataSet(airlineCSV);
  const x_matrix = DataSet.columnMatrix(independentVariables);
  const TS = new LSTMTimeSeries();
  await TS.train(x_matrix);
  const forecastData = TS.getTimeseriesDataSet([ [100 ], [200], [300], ])
  await TS.predict(forecastData.x_matrix); //=>[200,300,400]
}
main();

Special Thanks

License

MIT

jsonstack-model's People

Contributors

actions-user avatar dependabot[bot] avatar renovate-bot avatar semantic-release-bot avatar simoneb avatar yawetse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

simoneb

jsonstack-model's Issues

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.