RosettaCodeData/Task/Multiple-regression/Ruby/multiple-regression-1.rb

9 lines
191 B
Ruby
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
require 'matrix'
def regression_coefficients y, x
y = Matrix.column_vector y.map { |i| i.to_f }
x = Matrix.columns x.map { |xi| xi.map { |i| i.to_f }}
(x.t * x).inverse * x.t * y
end