scikit-learn-contrib / boruta_py

Python implementations of the Boruta all-relevant feature selection method.
BSD 3-Clause "New" or "Revised" License
1.46k stars 252 forks source link

AttributeError: module 'numpy' has no attribute 'int'. #113

Open notuntoward opened 1 year ago

notuntoward commented 1 year ago

When I run this:

boruta.fit(Xtrn, yTrn)

I get the error message below, indicating that boruta_py isn't compatible with numpy versions greater than 1.20. I had numpy version 1.24.2 installed. So I ran:

conda install "numpy<1.20"

and then I no longer got this error from Boruta. However, reverting to numpy<1.20 cost at least an hour of redoing my configuration of other packages.

A fix for this problem would be very helpful.

The error message


AttributeError Traceback (most recent call last) File :7

File ~/miniconda3/envs/vder2022/lib/python3.9/site-packages/boruta/boruta_py.py:201, in BorutaPy.fit(self, X, y) 188 def fit(self, X, y): 189 """ 190 Fits the Boruta feature selection with the provided estimator. 191 (...) 198 The target values. 199 """ --> 201 return self._fit(X, y)

File ~/miniconda3/envs/vder2022/lib/python3.9/site-packages/boruta/boruta_py.py:260, in BorutaPy._fit(self, X, y) 255 _iter = 1 256 # holds the decision about each feature: 257 # 0 - default state = tentative in original code 258 # 1 - accepted in original code 259 # -1 - rejected in original code --> 260 dec_reg = np.zeros(n_feat, dtype=np.int) 261 # counts how many times a given feature was more important than 262 # the best of the shadow features 263 hit_reg = np.zeros(n_feat, dtype=np.int) ...

AttributeError: module 'numpy' has no attribute 'int'. np.int was a deprecated alias for the builtin int. To avoid this error in existing code, use int by itself. Doing this will not modify any behavior and is safe. When replacing np.int, you may wish to use e.g. np.int64 or np.int32 to specify the precision. If you wish to review your current use, check the release note link for additional information. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

the-holsti commented 1 year ago

I had the same problem. I do not know if it helps you @notuntoward but I succesfully used BorutaPy with numpy==1.23.5. (numpy.int was removed in 1.24.0)

notuntoward commented 1 year ago

@the-holsti , that's good to know. Thanks. But hopefully, boruta_py will catch up soon, so that it remains viable into the future.

cluttered-cabinet commented 1 year ago

I was able to solve this by patching boruta_py.py and changing np.int -> int, np.float -> float, and np.bool -> bool, with the current version of NumPy

notuntoward commented 1 year ago

@cluttered-cabinet thanks for that info. It might make sense to put up a pull request with your changes, but checking the existing PRs, it looks like this package isn't maintained.

One of the PRs mentions ARFS as an alternative. I'm going to give it a try.

cluttered-cabinet commented 1 year ago

@notuntoward I'm debating on doing the same...seems like ARFS does have good docs and it's up to date :)

3zhang commented 1 year ago

It is already patched here. It is not patched on pypi. So replace boruta_py.py with the file on github should solve the issue.

luizhdramos commented 1 year ago

Just replace np.int, np.float and np.bool for int, floar and bool on Boruta boruta_py.py

aroyphillips commented 11 months ago

Will this be patched on pypi?

albarsil commented 10 months ago

Waiting this change on pypi 🙏