Code Monkey home page Code Monkey logo

gradient-descent-linear-regression's Introduction

gradient-descent-linear-regression

Pure python implementation of linear regression algorithm with gradient descent.

Demonstration of gradient descent algorithm on Linear Regression model containing one feature and one target.

Three techniques for linear regression We can fit a model to our data:

  1. By using sklearn
  2. By using Mathematical Formula
  3. By using Gradient Descent

All of them give same cost/accuracy

How they work

  1. sklearn implements a high level optimization code for optimizing the cost function. It's a readymade resource tool and only few lines of code can do the job.

  2. Mathematical formula gives exact values of its underlying parameters which make up the equation of regression line. Equation of regression line y = mx + c (slope-intercept form). We can directly find out m and c by using formulaes (m = slope, c = y intercept) m = Σ(x-x̅)(y-y̅) ∕ Σ(x-x̅)² c = y̅ - mx̅

  3. By using Gradient Descent: Gradient Descent is an optimizing algorithm. Initially we put random m and c. Goal is to minimize the cost function C = (1/m) × Σ(y-y_pred)² Requires a learning rate and number of iterations.

    We can construct a line on initial parameters and follow the steps:

    a. Compute the cost function.

    b. Apply GD and find optimal m and c.

    c. Repeat steps a & b until we get a constant minimum value of cost function.

Datasets used: www.superdatascience.com/pages/training from Machine Learning AZ course

gradient-descent-linear-regression's People

Stargazers

 avatar

Watchers

 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.