Giter Site home page Giter Site logo

didof / tf_linear-regression Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 302 KB

Created following @StephenGrider Udemy's course

Home Page: https://www.udemy.com/course/machine-learning-with-javascript/

JavaScript 93.88% HTML 6.12%
javascript tensorflowjs linear-regression gradient-descent gradient-descent-implementation

tf_linear-regression's Introduction

Linear Regression

Demo

Try it here!

How it works

When you instantiate the LinearRegression class it is obviously necessary to provide it with the set of features (1) and the set of labels (2). Optionally it is possible to pass a configuration object as follows:

  • learningRate (default 0.1): factor multiplied by the value of the derivative. It is used to decide how much to increase/decrease the weights for the next iteration of the gradient descent.

    • There are several methods considered to optimize the learning rate (Adam, Adagrad, RMSProp, Momentum) but in this demo a simple and custom method is implemented.
  • iterations (default 100): the number of times the gradient descent is recalculated. Technically, the higher the number of iterations, the more weights are representative of the training dataSet (assuming an opportun learning rate).

  • batchSize (default null): represents the number of items for each batch. If set to null, the gradient descent is calculated over the entire training dataset at each iteration. Setting it to any other number, at each iteration the dataset is sliced ​​in many batches.

The following methods can be called on the instance:

  • train: uses the gradient descent to calculate the weights related to the dataset provided and the selected options.

  • test: receives the testing dataset, returns R ^ 2 indicating the reliability of the line found.

  • predict: receives a dataset of features and returns the corresponding predictions based on the line found during training.

How to use

First install dependencies with npm install

In index.js you can tweak the options of the instantiation:

const regression = new LinearRegession(features, labels, {
  learningRate: 0.1,
  iterations: 30,
  batchSize: null, // number | null
})

You could also try to change the features and the class label:

let { features, labels, testFeatures, testLabels } = loadCSV('./cars.csv', {
  shuffle: true,
  splitTest: 50,
  dataColumns: ['horsepower', 'displacement', 'weight'], // features
  labelColumns: ['mpg'], // labels
})

Finally, run npm run regression:linear.

In console you can find info about the weights and R^2. Uncomment the plot section to obtain plots in the fs.

tf_linear-regression's People

Contributors

didof avatar

Watchers

 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.