[
  {
    "kind": "index",
    "content": "# TensorScript - Machine Learning and Neural Networks with Tensorflow\n\n[![Coverage Status](https://coveralls.io/repos/github/repetere/tensorscript/badge.svg?branch=master)](https://coveralls.io/github/repetere/tensorscript?branch=master) [![Build Status](https://travis-ci.org/repetere/tensorscript.svg?branch=master)](https://travis-ci.org/repetere/tensorscript)\n\n## Introduction\n\nThis 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).\n\n### [Read the manual](https://repetere.github.io/tensorscript/manual/overview.html)\n\n## List of Tensorflow models\n\n### Classification\n\n* Deep Learning Classification: [`DeepLearningClassification`](https://repetere.github.io/tensorscript/manual/usage.html#classification)\n* Logistic Regression: [`LogisticRegression`](https://repetere.github.io/tensorscript/manual/usage.html#classification)\n\n\n### Regression\n\n* Deep Learning Regression: [`DeepLearningRegression`](https://repetere.github.io/tensorscript/manual/usage.html#regression)\n* Multivariate Linear Regression: [`MultipleLinearRegression`](https://repetere.github.io/tensorscript/manual/usage.html#regression)\n\n### Artificial neural networks (ANN)\n\n* Multi-Layered Perceptrons: [`BaseNeuralNetwork`](https://repetere.github.io/tensorscript/manual/usage.html#neural-networks)\n\n### LSTM Time Series\n\n* Long Short Term Memory Time Series: [`LSTMTimeSeries`](https://repetere.github.io/tensorscript/manual/usage.html#timeseries)\n* Long Short Term Memory Multivariate Time Series: [`LSTMMultivariateTimeSeries`](https://repetere.github.io/tensorscript/manual/usage.html#timeseries)\n\n## Basic Usage\n\nTensorScript 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.\n\nPlease read more on tensorflow configuration options, specifying epochs, and using custom layers in [configuration](https://repetere.github.io/tensorscript/manual/overview.html#configuration).\n\n### Regression Examples\n\n```javascript\nimport { MultipleLinearRegression, DeepLearningRegression, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [ 'sqft', 'bedrooms',];\n  const dependentVariables = [ 'price', ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/portland_housing_data.csv');\n  const DataSet = new ms.DataSet(housingdataCSV);\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const MLR = new MultipleLinearRegression();\n  await MLR.train(x_matrix, y_matrix);\n  const DLR = new DeepLearningRegression();\n  await DLR.train(x_matrix, y_matrix);\n  //1600 sqft, 3 bedrooms\n  await MLR.predict([1650,3]); //=>[293081.46]\n  await DLR.predict([1650,3]); //=>[293081.46]\n}\nmain();\n```\n\n### Classification Examples\n\n```javascript\nimport { DeepLearningClassification, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [\n    'sepal_length_cm',\n    'sepal_width_cm',\n    'petal_length_cm',\n    'petal_width_cm',\n  ];\n  const dependentVariables = [\n    'plant_Iris-setosa',\n    'plant_Iris-versicolor',\n    'plant_Iris-virginica',\n  ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/iris_data.csv');\n  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {plant:'onehot'}, });\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const nnClassification = new DeepLearningClassification();\n  await nnClassification.train(x_matrix, y_matrix);\n  const input_x = [\n    [5.1, 3.5, 1.4, 0.2, ],\n    [6.3, 3.3, 6.0, 2.5, ],\n    [5.6, 3.0, 4.5, 1.5, ],\n    [5.0, 3.2, 1.2, 0.2, ],\n    [4.5, 2.3, 1.3, 0.3, ],\n  ];\n  const predictions = await nnClassification.predict(input_x); \n  const answers = await nnClassification.predict(input_x, { probability:false, });\n  /*\n    predictions = [\n      [ 0.989512026309967, 0.010471616871654987, 0.00001649192017794121, ],\n      [ 0.0000016141033256644732, 0.054614484310150146, 0.9453839063644409, ],\n      [ 0.001930746017023921, 0.6456733345985413, 0.3523959517478943, ],\n      [ 0.9875779747962952, 0.01239941269159317, 0.00002274810685776174, ],\n      [ 0.9545140862464905, 0.04520365223288536, 0.0002823179238475859, ],\n    ];\n    answers = [\n      [ 1, 0, 0, ], //setosa\n      [ 0, 0, 1, ], //virginica\n      [ 0, 1, 0, ], //versicolor\n      [ 1, 0, 0, ], //setosa\n      [ 1, 0, 0, ], //setosa\n    ];\n   */\n}\nmain();\n```\n\n```javascript\nimport { LogisticRegression, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [\n    'Age',\n    'EstimatedSalary',\n  ];\n  const dependentVariables = [\n    'Purchased',\n  ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/social_network_ads.csv');\n  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {Age:['scale','standard'],\n  EstimatedSalary:['scale','standard'],}, });\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const LR = new LogisticRegression();\n  await LR.train(x_matrix, y_matrix);\n  const input_x = [\n    [-0.062482849427819266, 0.30083326827486173,], //0\n    [0.7960601198093905, -1.1069168538010206,], //1\n    [0.7960601198093905, 0.12486450301537644,], //0\n    [0.4144854668150751, -0.49102617539282206,], //0\n    [0.3190918035664962, 0.5061301610775946,], //1\n  ];\n  const predictions = await LR.predict(input_x); // => [ [ 0 ], [ 0 ], [ 1 ], [ 0 ], [ 1 ] ];\n}\nmain();\n```\n\n### Time Series Example\n\n```javascript\nimport { LSTMTimeSeries, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const dependentVariables = [\n    'Passengers',\n  ];\n  const airlineCSV = await ms.csv.loadCSV('./test/mock/data/airline-sales.csv');\n  const DataSet = new ms.DataSet(airlineCSV);\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const TS = new LSTMTimeSeries();\n  await TS.train(x_matrix);\n  const forecastData = TS.getTimeseriesDataSet([ [100 ], [200], [300], ])\n  await TS.predict(forecastData.x_matrix); //=>[200,300,400]\n}\nmain();\n```\n\n### Testing\n\n```sh\n$ npm i\n$ npm test\n```\n\n### Contributing\n\nFork, write tests and create a pull request!\n\n### Misc\n\nAs of Node 8, ES modules are still used behind a flag, when running natively as an ES module\n\n```sh\n$ node --experimental-modules manual/examples/ex_regression-boston.mjs\n# Also there are native bindings that require Python 2.x, make sure if you're using Anaconda, you build with your Python 2.x bin\n$ npm i --python=/usr/bin/python\n ```\n\n ### Special Thanks\n - [Machine Learning Mastery](https://machinelearningmastery.com/)\n - [Super Data Science](https://www.superdatascience.com/)\n - [Python Programming](https://pythonprogramming.net/)\n - [Towards Data Science](https://towardsdatascience.com/)\n - [ml.js](https://github.com/mljs/ml)\n\nLicense\n----\n\nMIT",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/README.md",
    "name": "./README.md",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manualIndex",
    "content": "# TensorScript - Machine Learning and Neural Networks with Tensorflow\n\n[![Coverage Status](https://coveralls.io/repos/github/repetere/tensorscript/badge.svg?branch=master)](https://coveralls.io/github/repetere/tensorscript?branch=master) [![Build Status](https://travis-ci.org/repetere/tensorscript.svg?branch=master)](https://travis-ci.org/repetere/tensorscript)\n\n## Introduction\n\nThis 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).\n\n### [Read the manual](https://repetere.github.io/tensorscript/manual/overview.html)\n\n## List of Tensorflow models\n\n### Classification\n\n* Deep Learning Classification: [`DeepLearningClassification`](https://repetere.github.io/tensorscript/manual/usage.html#classification)\n* Logistic Regression: [`LogisticRegression`](https://repetere.github.io/tensorscript/manual/usage.html#classification)\n\n\n### Regression\n\n* Deep Learning Regression: [`DeepLearningRegression`](https://repetere.github.io/tensorscript/manual/usage.html#regression)\n* Multivariate Linear Regression: [`MultipleLinearRegression`](https://repetere.github.io/tensorscript/manual/usage.html#regression)\n\n### Artificial neural networks (ANN)\n\n* Multi-Layered Perceptrons: [`BaseNeuralNetwork`](https://repetere.github.io/tensorscript/manual/usage.html#neural-networks)\n\n### LSTM Time Series\n\n* Long Short Term Memory Time Series: [`LSTMTimeSeries`](https://repetere.github.io/tensorscript/manual/usage.html#timeseries)\n* Long Short Term Memory Multivariate Time Series: [`LSTMMultivariateTimeSeries`](https://repetere.github.io/tensorscript/manual/usage.html#timeseries)\n\n## Basic Usage\n\nTensorScript 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.\n\nPlease read more on tensorflow configuration options, specifying epochs, and using custom layers in [configuration](https://repetere.github.io/tensorscript/manual/overview.html#configuration).\n\n### Regression Examples\n\n```javascript\nimport { MultipleLinearRegression, DeepLearningRegression, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [ 'sqft', 'bedrooms',];\n  const dependentVariables = [ 'price', ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/portland_housing_data.csv');\n  const DataSet = new ms.DataSet(housingdataCSV);\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const MLR = new MultipleLinearRegression();\n  await MLR.train(x_matrix, y_matrix);\n  const DLR = new DeepLearningRegression();\n  await DLR.train(x_matrix, y_matrix);\n  //1600 sqft, 3 bedrooms\n  await MLR.predict([1650,3]); //=>[293081.46]\n  await DLR.predict([1650,3]); //=>[293081.46]\n}\nmain();\n```\n\n### Classification Examples\n\n```javascript\nimport { DeepLearningClassification, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [\n    'sepal_length_cm',\n    'sepal_width_cm',\n    'petal_length_cm',\n    'petal_width_cm',\n  ];\n  const dependentVariables = [\n    'plant_Iris-setosa',\n    'plant_Iris-versicolor',\n    'plant_Iris-virginica',\n  ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/iris_data.csv');\n  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {plant:'onehot'}, });\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const nnClassification = new DeepLearningClassification();\n  await nnClassification.train(x_matrix, y_matrix);\n  const input_x = [\n    [5.1, 3.5, 1.4, 0.2, ],\n    [6.3, 3.3, 6.0, 2.5, ],\n    [5.6, 3.0, 4.5, 1.5, ],\n    [5.0, 3.2, 1.2, 0.2, ],\n    [4.5, 2.3, 1.3, 0.3, ],\n  ];\n  const predictions = await nnClassification.predict(input_x); \n  const answers = await nnClassification.predict(input_x, { probability:false, });\n  /*\n    predictions = [\n      [ 0.989512026309967, 0.010471616871654987, 0.00001649192017794121, ],\n      [ 0.0000016141033256644732, 0.054614484310150146, 0.9453839063644409, ],\n      [ 0.001930746017023921, 0.6456733345985413, 0.3523959517478943, ],\n      [ 0.9875779747962952, 0.01239941269159317, 0.00002274810685776174, ],\n      [ 0.9545140862464905, 0.04520365223288536, 0.0002823179238475859, ],\n    ];\n    answers = [\n      [ 1, 0, 0, ], //setosa\n      [ 0, 0, 1, ], //virginica\n      [ 0, 1, 0, ], //versicolor\n      [ 1, 0, 0, ], //setosa\n      [ 1, 0, 0, ], //setosa\n    ];\n   */\n}\nmain();\n```\n\n```javascript\nimport { LogisticRegression, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const independentVariables = [\n    'Age',\n    'EstimatedSalary',\n  ];\n  const dependentVariables = [\n    'Purchased',\n  ];\n  const housingdataCSV = await ms.csv.loadCSV('./test/mock/data/social_network_ads.csv');\n  const DataSet = new ms.DataSet(housingdataCSV).fitColumns({ columns: {Age:['scale','standard'],\n  EstimatedSalary:['scale','standard'],}, });\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const y_matrix = DataSet.columnMatrix(dependentVariables);\n  const LR = new LogisticRegression();\n  await LR.train(x_matrix, y_matrix);\n  const input_x = [\n    [-0.062482849427819266, 0.30083326827486173,], //0\n    [0.7960601198093905, -1.1069168538010206,], //1\n    [0.7960601198093905, 0.12486450301537644,], //0\n    [0.4144854668150751, -0.49102617539282206,], //0\n    [0.3190918035664962, 0.5061301610775946,], //1\n  ];\n  const predictions = await LR.predict(input_x); // => [ [ 0 ], [ 0 ], [ 1 ], [ 0 ], [ 1 ] ];\n}\nmain();\n```\n\n### Time Series Example\n\n```javascript\nimport { LSTMTimeSeries, } from 'tensorscript';\nimport ms from 'modelscript';\n\nasync function main(){\n  const dependentVariables = [\n    'Passengers',\n  ];\n  const airlineCSV = await ms.csv.loadCSV('./test/mock/data/airline-sales.csv');\n  const DataSet = new ms.DataSet(airlineCSV);\n  const x_matrix = DataSet.columnMatrix(independentVariables);\n  const TS = new LSTMTimeSeries();\n  await TS.train(x_matrix);\n  const forecastData = TS.getTimeseriesDataSet([ [100 ], [200], [300], ])\n  await TS.predict(forecastData.x_matrix); //=>[200,300,400]\n}\nmain();\n```\n\n### Testing\n\n```sh\n$ npm i\n$ npm test\n```\n\n### Contributing\n\nFork, write tests and create a pull request!\n\n### Misc\n\nAs of Node 8, ES modules are still used behind a flag, when running natively as an ES module\n\n```sh\n$ node --experimental-modules manual/examples/ex_regression-boston.mjs\n# Also there are native bindings that require Python 2.x, make sure if you're using Anaconda, you build with your Python 2.x bin\n$ npm i --python=/usr/bin/python\n ```\n\n ### Special Thanks\n - [Machine Learning Mastery](https://machinelearningmastery.com/)\n - [Super Data Science](https://www.superdatascience.com/)\n - [Python Programming](https://pythonprogramming.net/)\n - [Towards Data Science](https://towardsdatascience.com/)\n - [ml.js](https://github.com/mljs/ml)\n\nLicense\n----\n\nMIT",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/README.md",
    "name": "./README.md",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manualAsset",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/manual/asset",
    "name": "./manual/asset",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manual",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/manual/overview.md",
    "name": "./manual/overview.md",
    "content": "# Overview\r\n\r\nAll of the model building classes are structured similarly to ml.js models. Each model has three shared components regardless if it's a regression, classification or time series model.\r\n\r\nThis library was built to quickly implement [Tensorflow](https://js.tensorflow.org) and [Keras](https://js.tensorflow.org/tutorials/import-keras.html) models in JavaScript.\r\n\r\n## Configuration\r\n\r\nAll of the model configuration is managed during creating an instance of the class. All models have `fit` and `compile` properties that are assigned to the instance `settings` property.\r\n\r\nYou can also pass the Tensorflow reference to be used, as a configuration property if you want to use the compiled C++ or GPU via CUDA versions on the `tf` property;\r\n\r\n* `this.settings.compile` is passed to `tensorflow.model.compile` and contains the configuration for optimizers ([`read more`](https://js.tensorflow.org/api/latest/#tf.Model.compile)).\r\n* `this.settings.fit` is passed to `tensorflow.model.fit` and contains the configuration for model fitting ([`read more`](https://js.tensorflow.org/api/latest/#tf.Sequential.fit))\r\n\r\n### Model constructor example\r\n\r\n```javascript\r\nimport { MultipleLinearRegression, } from 'tensorscript';\r\nimport tf from '@tensorflow/tfjs-node-gpu';\r\n\r\nconst MLR = new MultipleLinearRegression({\r\n  fit:{\r\n    epochs:500,\r\n    batchSize:5,\r\n  },\r\n  compile:{\r\n    loss: 'meanSquaredError',\r\n    optimizer: 'adam',\r\n  },\r\n},{\r\n  tf,\r\n});\r\n```\r\n\r\nEach constructor takes two parameters `settings` and `properties`. As in the example above, *settings* are used to configure tensorflow objects and properties are used to configure tensorscript (like which version of tensorflow to use).\r\n\r\n## Training\r\n\r\nAll tensorflow models train asynchronously, therefore all tensorscript model train functions are all asynchronous. Always pass dependent and independent variables as matrix inputs.\r\n\r\nTime series models can be trained with only one input matrix.\r\n\r\n### Training example\r\n\r\n```javascript\r\n\r\nimport { MultipleLinearRegression, } from 'tensorscript';\r\n\r\nasync function main(){\r\n  const MLR = new MultipleLinearRegression();\r\n  const x = [ [1], [2] ];\r\n  const y = [ [3], [4] ];\r\n  await MLR.train(x,y);\r\n}\r\n```\r\n\r\n## Predicting\r\n\r\nAll prediction inputs must be the same shape as training inputs. TensorScript provides an asynchronous predict method that converts tensor values to javascript objects. If you want the tensor from tensorflow, use the calculate method instead.\r\n\r\n### Predicting example\r\n\r\n```javascript\r\nimport { MultipleLinearRegression, } from 'tensorscript';\r\n\r\nasync function main(){\r\n  const MLR = new MultipleLinearRegression();\r\n  const x = [ [1], [2] ];\r\n  const y = [ [3], [4] ];\r\n  await MLR.train(x,y);\r\n\r\n  await MLR.predict([[3]]) //=> [[5]];\r\n  const tensorPrediction = await MLR.calculate([[3]]) //=> [[5]];\r\n  tensorPrediction.data()\r\n    .then(tensors=> /*Typed Array*/)\r\n}\r\n```\r\n\r\n## Examples\r\n\r\nFor more examples on how to do feature scaling and more, check out the *[Examples folder](https://github.com/repetere/tensorscript/tree/master/manual/examples)*.",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manual",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/manual/usage.md",
    "name": "./manual/usage.md",
    "content": "# Usage\r\n\r\nUsage examples are below\r\n\r\n## Classification\r\n\r\n- Deep Learning Classification with Iris data set. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_classification-iris.mjs)\r\n- Logistic Regression Classification with social media ads. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_classification-social.mjs)\r\n\r\n## Regression\r\n\r\n- Deep Learning Regression with Boston housing data set. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_regression-boston.mjs)\r\n- Multiple Linear Regression with Portland housing data set. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_regression-portland.mjs)\r\n\r\n## Time Series\r\n\r\n- Long Short Term Memory with Airline prices. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_timeseries-airline.mjs)\r\n\r\n## Neural Network\r\n\r\n- MLP with dense layers and the Portland housing data. [link](https://github.com/repetere/tensorscript/blob/master/manual/examples/ex_nn-portland.mjs)\r\n",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manual",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/manual/faq.md",
    "name": "./manual/faq.md",
    "content": "# Frequently Asked Questions\r\n\r\n## Scaling\r\n\r\n- **How do I scale and descale my inputs?**\r\n  - The library is only for model create, data engineering and modeling is typically handled elsewhere\r\n  - Check out the regression examples (hint: use [ModelScript](https://repetere.github.io/modelscript/)).\r\n- **How do I cross validate, test/train split, K-fold, etc?**\r\n  - (See above) The library is only for model create, data engineering and modeling is typically handled elsewhere\r\n  - Check out the code examples (hint: use [ModelScript](https://repetere.github.io/modelscript/)).",
    "static": true,
    "access": "public"
  },
  {
    "kind": "manual",
    "longname": "/Users/yawjosephetse/Developer/github/repetere/tensorscript/CHANGELOG.md",
    "name": "./CHANGELOG.md",
    "content": "# Changelog\r\n\r\n## 1.4.0 (2019-05-09)\r\n- **Feat**\r\n  - Added support for Model Saving and Loading\r\n\r\n## 1.0.0 (2018-07-30)\r\n\r\n- **Feat**\r\n  - First Initial Release\r\n- **Fix**\r\n  - N/A\r\n- **Chore**\r\n  - Allow for multistep future forecasts in multivariate timeseries.\r\n  - Add basic clustering example.\r\n",
    "static": true,
    "access": "public"
  }
]