• Stars
    star
    535
  • Rank 82,367 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Example demonstrating how gradient descent may be used to solve a linear regression problem

Gradient Descent Example for Linear Regression

This example project demonstrates how the gradient descent algorithm may be used to solve a linear regression problem. A more detailed description of this example can be found here.

Code Requirements

The example code is in Python (version 2.6 or higher will work). The only other requirement is NumPy.

Description

This code demonstrates how a gradient descent search may be used to solve the linear regression problem of fitting a line to a set of points. In this problem, we wish to model a set of points using a line. The line model is defined by two parameters - the line's slope m, and y-intercept b. Gradient descent attemps to find the best values for these parameters, subject to an error function.

The code contains a main function called run. This function defines a set of parameters used in the gradient descent algorithm including an initial guess of the line slope and y-intercept, the learning rate to use, and the number of iterations to run gradient descent for.

initial_b = 0 # initial y-intercept guess
initial_m = 0 # initial slope guess
num_iterations = 1000

Using these parameters a gradient descent search is executed on a sample data set of 100 ponts. Here is a visualization of the search running for 200 iterations using an initial guess of m = 0, b = 0, and a learning rate of 0.000005.

Execution

To run the example, simply run the gradient_descent_example.py file using Python

python gradient_descent_example.py

The output will look like this

Starting gradient descent at b = 0, m = 0, error = 5565.10783448
Running...
After 1000 iterations b = 0.0889365199374, m = 1.47774408519, error = 112.614810116

More Repositories

1

MeanShift_py

Simple implementation of mean shift clustering in python
Python
286
star
2

palette-maker

Palette Maker is an interactive web tool that allows you to explore different approaches to extract color palettes from images
JavaScript
137
star
3

MeanShift_cpp

Mean shift clustering Implementation in C++
C++
90
star
4

react-redux-typescript

Project template for projects that use React, Redux, and TypeScript
TypeScript
38
star
5

CentralLimitTheoremDemo

Python
25
star
6

ruby-excel-library-examples

Example code for reading Excel files in ruby with different libraries.
Ruby
23
star
7

S3.FMA

Amazon S3 File Manager API in Python. S3.FMA is a thin wrapper around boto to perform specific high level file management tasks on an AWS S3 Bucket.
Python
20
star
8

swift-type-inference-bug

This project contains code that reproduces a bug that prevents the Swift compiler from being able to efficiently perform type inference on semi-simple dictionary or array literals.
Swift
17
star
9

beacon-scanner

Swift
14
star
10

ibeacon-finder

Simple iOS iBeacon app skeleton in Swift. Searches for an iBeacon in monitoring and ranging mode and prints results. This app contains no meaningful UI.
Swift
11
star
11

SwiftForecast

API Wrapper around The Dark Sky Forecast API in Swift
Swift
4
star
12

rickshaw_examples

HTML
4
star
13

react-native-demo-project

Simple cross platform app written with react native. Uses cross platform tabbed navigation, and loads and displays trending gifs from Giphy
JavaScript
2
star
14

spacemacs-configuration

Personal Spacemacs dotfile
Emacs Lisp
2
star
15

DataStructuresCSharp

Data structure implementations in C#
C#
1
star
16

algorithms

implementations for various algorithms
C#
1
star
17

AlgorithmsPython

Implementations of various algorithms in python
Python
1
star