Skip to content

Instantly share code, notes, and snippets.

@charly
charly / gist:8114471
Last active January 1, 2016 07:49 — forked from Serabe/gist:990667
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