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

AttributeError: module 'numpy' has no attribute 'bool' when using BorutaPy with RandomForestClassifier #120

Open
codewithawr opened this issue Sep 8, 2023 · 3 comments

Comments

@codewithawr
Copy link

codewithawr commented Sep 8, 2023

I encountered an error while using BorutaPy with a RandomForestClassifier model. The error message states "AttributeError: module 'numpy' has no attribute 'bool'." The error suggests that BorutaPy is trying to use numpy.bool, which was a deprecated alias for the built-in bool. To avoid this error in existing code, we should use bool by itself. If the specific intention was to use the numpy scalar type, we should use numpy.bool_.

  • Also it happening with int values numpy wants numpy.int64 or numpy.int32

Steps to Reproduce:

Bach

pip install numpy==1.25.2 Boruta==0.3 scikit-learn==1.3.0 pandas==2.1.0

Code

import numpy as np
from boruta import BorutaPy
from sklearn.ensemble import RandomForestClassifier

# Create a sample dataset with boolean features and labels
num_samples = 100
num_features = 5

# Generate random binary features (0 or 1)
x_train_rfe = np.random.randint(2, size=(num_samples, num_features), dtype=bool)

# Generate random binary labels (0 or 1)
y_train = np.random.randint(2, size=num_samples)

# Create a BorutaPy instance with a RandomForestClassifier
bl_model_ob = RandomForestClassifier(n_jobs=-1, max_depth=5, random_state=1) 
boruta_selection = BorutaPy(estimator=bl_model_ob, n_estimators='auto', verbose=2, random_state=1)

# Attempt to fit the BorutaPy model with the boolean dataset
boruta_selection.fit(x_train_rfe, y_train)


Behavior:

Error

--> 372     depth = self.estimator.get_params()['max_depth']
    373     if depth == None:
    374         depth = 10

KeyError: 'max_depth'

Additional Information:

Python Version: 3.9.12
Operating System: Windows

@codewithawr
Copy link
Author

codewithawr commented Sep 9, 2023

hear what i am doing for it to work

# Reassigning np.int to np.int64
np.int = np.int64

# Reassigning np.float to np.float64
np.float = np.float64

# Reassigning np.bool to np.bool_
np.bool = np.bool_

it a temporary solution might help someone

@ErikHartman
Copy link

There is an open PR fixing this. Basically just change all np.type to np.type_

It seems like no one is approving PRs though.

@VEZcoding
Copy link

Someone should indeed updated this package so it won't clash with changes to numpy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants