Created
May 25, 2011 09:38
-
-
Save Serabe/990667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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