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: 'LocalClassifierPerNode' object has no attribute '_validate_data' #140

Open
pbahr opened this issue Jan 14, 2025 · 1 comment

Comments

@pbahr
Copy link

pbahr commented Jan 14, 2025

Describe the bug
Hi there,

I have pip installed the library and tried to run the Hello HiClass code.

Running the code, I get this error:

AttributeError: 'LocalClassifierPerNode' object has no attribute '_validate_data'

When I looked at the code, I see this line in the hiclass/HierarchicalClassifier.py file:

def _pre_fit(self, X, y, sample_weight):
# Check that X and y have correct shape
# and convert them to np.ndarray if need be

    if not self.bert:
        self.X_, self.y_ = self._validate_data(
            X, y, multi_output=True, accept_sparse="csr", allow_nd=True
        )

...

But I couldn't find the implementation for _validate_data() anywhere in the other classes, e.g. LocalClassifierPerNode

To Reproduce
Steps to reproduce the behavior:

  1. pip install hiclass['xai','ray']
  2. run the Hello HiClass code
  3. You'll probably get the same error as me

Expected behavior
Print out the predictions for the test set

Desktop (please complete the following information):

  • Running the code in the notebook environment for Azure Machine Learning
  • hiClass 4.13.3
  • numpy 1.21.6
  • scipy 1.10.1
  • scikit-learn 0.22.1
@pbahr
Copy link
Author

pbahr commented Jan 15, 2025

Stack trace:
AttributeError Traceback (most recent call last)
Cell In[7], line 20
17 classifier = LocalClassifierPerNode(local_classifier=rf)
19 # Train local classifier per node
---> 20 classifier.fit(X_train, Y_train)
22 # Predict
23 predictions = classifier.predict(X_test)

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/hiclass/LocalClassifierPerNode.py:155, in LocalClassifierPerNode.fit(self, X, y, sample_weight)
134 """
135 Fit a local classifier per node.
136
(...)
152 Fitted estimator.
153 """
154 # Execute common methods necessary before fitting
--> 155 super().pre_fit(X, y, sample_weight)
157 # Initialize policy
158 self.binary_policy
= self._initialize_binary_policy(calibration=False)

File /anaconda/envs/azureml_py38/lib/python3.8/site-packages/hiclass/HierarchicalClassifier.py:159, in HierarchicalClassifier.pre_fit(self, X, y, sample_weight)
154 def pre_fit(self, X, y, sample_weight):
155 # Check that X and y have correct shape
156 # and convert them to np.ndarray if need be
158 if not self.bert:
--> 159 self.X
, self.y
= self.validate_data(
160 X, y, multi_output=True, accept_sparse="csr", allow_nd=True
161 )
162 else:
163 self.X
= np.array(X)

AttributeError: 'LocalClassifierPerNode' object has no attribute '_validate_data'

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

1 participant