
./svd.pl _ dataset.csv can be downloaded from here . I will now just give him the part that does the actual training. # SVD: , while (abs($old_rmse - $rmse) > 0.00001 ) { $old_rmse = $rmse; $rmse = 0; foreach my $u ( keys %l ) { foreach my $v ( keys %{$l{$u}} ) { # $err = $l{$u}{$v} - ($mu + $b_u[$u] + $b_v[$v] + dot($u_f[$u], $v_f[$v]) ); # $rmse += $err * $err; # ... $mu += $eta * $err; $b_u[$u] += $eta * ($err - $lambda2 * $b_u[$u]); $b_v[$v] += $eta * ($err - $lambda2 * $b_v[$v]); # ... for (my $f=0; $f < $features; ++$f) { $u_f[$u][$f] += $eta * ($err * $v_f[$v][$f] - $lambda2 * $u_f[$u][$f]); $v_f[$v][$f] += $eta * ($err * $u_f[$u][$f] - $lambda2 * $v_f[$v][$f]); } } } ++$iter_no; # , RMSE $rmse = sqrt($rmse / $total); print "Iteration $iter_no:\tRMSE=" . $rmse . "\n"; # RMSE , if ($rmse > $old_rmse - $threshold) { $eta = $eta * 0.66; $threshold = $threshold * 0.5; } } 
Read 5 users and 5 urls.
Iteration 1: RMSE = 1.92845291697284
Iteration 2: RMSE = 1.28481736445124
Iteration 3: RMSE = 1.14159530044051
...
Iteration 808: RMSE = 0.0580161117835789
Iteration 809: RMSE = 0.0580061123741253
mu: 2.54559533638261
User base: 0.7271 0.1626 0.7139 1.9097 -0.9677
Item base: 0.8450 0.6593 0.2731 0.7328 0.0354
User features
user 0: -0.5087 -0.8326
user 1: 1.0220 1.2826
user 2: -0.9509 0.2792
user 3: 0.1031 -0.4814
user 4: 0.6095 0.0557
Item features:
Item 0: -0.8368 0.2511
item 1: 1.1101 0.4120
item 2: -0.4159 -0.4073
item 3: -0.3130 -0.9115
item 4: 0.6408 1.2205 What have we got as a result? Approximately what we expected. Users received basic predictors in accordance with their kindness: Petrovich turned out to be an evil spectator, and the rest, on the contrary, were kind, especially Zhannochka. Films received basic predictors in accordance with “overall quality” (expressed, of course, through evaluations).2.5456 + 0.7271 + 0.8450 + (-0.5087) * (- 0.8368) + (-0.8326) * 0.2511 = 4.3343143.
Source: https://habr.com/ru/post/141959/
All Articles