Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Linear Regression Most Efficient algorithm calc Line of Best Fit

Linear Regression Most Efficient algorithm calc Line of Best Fit

Scheduled Pinned Locked Moved Algorithms
comalgorithmsdata-structurestoolstutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A
    wrote on last edited by
    #1

    I have a group of points that I need to plot on a graph and calculate the line of best fit(Slope and Intercept) in a programming language. for example x 0 1 2 3 4 y 40 41 45 41 47 At the moment I am using and have implemented the Least Squares algorithm here http://en.wikipedia.org/wiki/Least_squares[^] I was wondering whether anyone knows of a computationally more efficient algorithm with close to the same accuracy and be able to explain how the algorithm works? Thanks in advance :)

    My blog:[^]

    P 1 Reply Last reply
    0
    • A A

      I have a group of points that I need to plot on a graph and calculate the line of best fit(Slope and Intercept) in a programming language. for example x 0 1 2 3 4 y 40 41 45 41 47 At the moment I am using and have implemented the Least Squares algorithm here http://en.wikipedia.org/wiki/Least_squares[^] I was wondering whether anyone knows of a computationally more efficient algorithm with close to the same accuracy and be able to explain how the algorithm works? Thanks in advance :)

      My blog:[^]

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      A decent implementation of linear fitting by LSQ should run in O(n) time and O(1) space. One pass over the data, accumulating sum(x), sum(y), sum(x*x) and sum(x*y) then crunch those four (and n) to get the answer. If you're just doing a simple linear fit, DON'T get sucked into all the matrix stuff. Waaaaay overkill. Cheers, Peter [edit]forgot sum(y)[/edit]

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups