From 9d693723ba7bcf380182e8bd4d622f6d8eff4e3a Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Sun, 2 Mar 2014 16:36:13 +0100 Subject: logistic regression --- lin_reg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lin_reg') diff --git a/lin_reg b/lin_reg index 3546c3e..d512104 100755 --- a/lin_reg +++ b/lin_reg @@ -44,13 +44,13 @@ def main i += 1 u = SparseVector.new zeros overall_loss = 0.0 - data.each_with_index { |d,j| - loss = model.dot(d) - t[j] + data.each_with_index { |x,j| + loss = model.dot(x) - t[j] overall_loss += loss**2 - u += d * (loss * (1.0/t.size)) + u += x * loss } STDERR.write "#{i} #{overall_loss/data.size}\n" if cfg[:show_loss] - u *= cfg[:learning_rate] + u *= cfg[:learning_rate]*(1.0/t.size) model -= u if model.approx_eql? prev_model stop += 1 -- cgit v1.2.3