Skip to content

Instantly share code, notes, and snippets.

@Serabe
Created May 25, 2011 09:38
Show Gist options
  • Save Serabe/990667 to your computer and use it in GitHub Desktop.
Save Serabe/990667 to your computer and use it in GitHub Desktop.
require 'matrix'
def regression x, y, degree
x_data = x.map {|xi| (0..degree).map{|pow| (xi**pow) }}
mx = Matrix[*x_data]
my = Matrix.column_vector y
((mx.t * mx).inv * mx.t * my).transpose.to_a[0].reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment