Skip to content

Commit e9cb067

Browse files
authored
Fix division by zero exception (#11)
* Fix division by zero in slopeone predictor * Fix styling
1 parent 8ff3ba8 commit e9cb067

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"php": "^7.4|^8.0|^8.1"
2525
},
2626
"require-dev": {
27-
"squizlabs/php_codesniffer": "^3.4",
28-
"phpstan/phpstan": "^0.12",
29-
"pestphp/pest": "^1.18"
27+
"phpstan/phpstan": "^1.10",
28+
"pestphp/pest": "^1.23",
29+
"friendsofphp/php-cs-fixer": "^3.34"
3030
},
3131
"autoload": {
3232
"psr-4": {

src/Algorithms/Slopeone/Predictor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function getPrediction(array $evaluation, string $target): float
3535
$sum += ($value + $vectors[1][$key]) * $card;
3636
$freq += $card;
3737
}
38-
$predValue = $sum / $freq;
38+
39+
$predValue = $sum / ($freq !== 0 ? $freq : 1);
3940

4041
return round($predValue, $this->vector->getScale());
4142
}

0 commit comments

Comments
 (0)