Skip to content

Commit

Permalink
Fix division by zero exception (#11)
Browse files Browse the repository at this point in the history
* Fix division by zero in slopeone predictor

* Fix styling
  • Loading branch information
mhdcodes authored Oct 5, 2023
1 parent 8ff3ba8 commit e9cb067
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"php": "^7.4|^8.0|^8.1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"phpstan/phpstan": "^0.12",
"pestphp/pest": "^1.18"
"phpstan/phpstan": "^1.10",
"pestphp/pest": "^1.23",
"friendsofphp/php-cs-fixer": "^3.34"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 2 additions & 1 deletion src/Algorithms/Slopeone/Predictor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public function getPrediction(array $evaluation, string $target): float
$sum += ($value + $vectors[1][$key]) * $card;
$freq += $card;
}
$predValue = $sum / $freq;

$predValue = $sum / ($freq !== 0 ? $freq : 1);

return round($predValue, $this->vector->getScale());
}
Expand Down

0 comments on commit e9cb067

Please sign in to comment.