summaryrefslogtreecommitdiff
path: root/lin_reg
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-03-02 16:36:13 +0100
committerPatrick Simianer <p@simianer.de>2014-03-02 16:36:13 +0100
commit9d693723ba7bcf380182e8bd4d622f6d8eff4e3a (patch)
treee7c489836a41bdbcc30c9690108ed9e3a77b965d /lin_reg
parent38862b7e0cde7ac7285169c10e1377357ea24488 (diff)
logistic regression
Diffstat (limited to 'lin_reg')
-rwxr-xr-xlin_reg8
1 files changed, 4 insertions, 4 deletions
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