Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Division by zero error #10

Closed
imhaggarwal opened this issue Oct 4, 2023 · 3 comments · Fixed by #11
Closed

Division by zero error #10

imhaggarwal opened this issue Oct 4, 2023 · 3 comments · Fixed by #11
Assignees
Labels
bug Something isn't working

Comments

@imhaggarwal
Copy link

First of all thank you for developing such an excellend library.
While predicting, I sometimes get Division by zero error depending on the input data for prediction. Moreover, it also gives this error verying the algorithm used for training.
Is there any condition under which it behaves like this which I'm missing? I'm attaching the error screenshot which might help in debugging.
Thank you
image

@the-dijkstra
Copy link
Member

from what I see in the picture I belive the error is on your end, on line 38 you are trying to divide $predValue = $sum / $freq

in the use case where $vectors[0] is empty, the loop will be skipped and the value of $freq in that case will be 0. so you need to check first the value of $freq before you divide.

@the-dijkstra the-dijkstra self-assigned this Oct 4, 2023
@imhaggarwal
Copy link
Author

Thanks for your reply. I'm sorry I think I am missing one important detail.
The code which is there in the screenshot is from the file phpjuice\opencf\src\Algorithms\Slopeone\Predictor.php . I have not written this code, I just called the getPrediction function.

@imhaggarwal imhaggarwal reopened this Oct 5, 2023
@the-dijkstra
Copy link
Member

hmm I will check that it's been a while since I worked on this package I will make sure to fix the issue.

@the-dijkstra the-dijkstra linked a pull request Oct 5, 2023 that will close this issue
@the-dijkstra the-dijkstra added the bug Something isn't working label Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants