June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,10 +1,10 @@
|
|||
require 'matrix'
|
||||
|
||||
def regress x, y, degree
|
||||
x_data = x.map { |xi| (0..degree).map { |pow| (xi**pow).to_f } }
|
||||
x_data = x.map { |xi| (0..degree).map { |pow| (xi**pow).to_r } }
|
||||
|
||||
mx = Matrix[*x_data]
|
||||
my = Matrix.column_vector(y)
|
||||
|
||||
((mx.t * mx).inv * mx.t * my).transpose.to_a[0]
|
||||
((mx.t * mx).inv * mx.t * my).transpose.to_a[0].map(&:to_f)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
betas = regress [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
[1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321],
|
||||
2
|
||||
|
||||
p betas
|
||||
p regress([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
[1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321],
|
||||
2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue