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

Bug Report: RuntimeWarning: invalid value encountered in scalar divide #112

Closed
erkankarabulut opened this issue Mar 3, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@erkankarabulut
Copy link

In rule.py, lines 224-226, and 244-246, the following lines throw an error if the divisor part is 0:

acc += (attribute.max_val - attribute.min_val) / (
                    feature_max - feature_min
                )

For instance, if all the values are same in a column, that this lines throws the following warning message: RuntimeWarning: invalid value encountered in scalar divide acc += (attribute.max_val - attribute.min_val) / (...

@firefly-cpp firefly-cpp added the bug Something isn't working label Mar 11, 2024
@firefly-cpp
Copy link
Owner

@erkankarabulut, thank you for reporting this bug. Please provide a minimal example that resulted in an exception. We would like to have more information before changing the code.

@erkankarabulut
Copy link
Author

erkankarabulut commented Mar 12, 2024

Hello @firefly-cpp! Here is a minimal example that will result in the warning message I mentioned:

import pandas as pd
from niaarm import get_rules, Dataset
from niapy.algorithms.basic import HarrisHawksOptimization

data = [["feature1", "feature2", "feature3"], [10, 20, 30], [10, 20, 30], [10, 20, 30]]
algo = HarrisHawksOptimization(population_size)
metrics = ['confidence']

frame = pd.DataFrame(data[1:], columns=data[0])
dataset = Dataset(frame)
rules, run_time = get_rules(dataset, algo, metrics, max_iters, logging=False)

In this case, feature_max and feature_min will be equal and the divisor part on the lines I mentioned will be equal to 0.

I see that acc is used in amplitude calculation. I would fix it myself and open a pull request, but I was not sure how would the amplitude be calculated in this case.

@firefly-cpp
Copy link
Owner

Thanks @erkankarabulut. Please patch it and submit a pull request.

@erkankarabulut
Copy link
Author

@firefly-cpp I wasn't sure how to fix this, but I guess increasing acc by 1 during amplitude calculation instead of the division operation seemed correct.

Could you verify this, please? I opened a PR as well: #113. I am not sure how to link PRs to issues.

@firefly-cpp
Copy link
Owner

The new version is now on Pypi. @erkankarabulut, please check it out and test it. In case of any other bugs, feel free to open a ticket and submit a pull request.

By the way, there is also a Julia version: https://github.com/firefly-cpp/NiaARM.jl while there is also an R version, but is very immature: https://github.com/firefly-cpp/niarules

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

No branches or pull requests

3 participants