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

Add support for allowing multi-dimensional inputs (ndim > 2) #minor #97

Merged

Conversation

ashishpatel16
Copy link
Collaborator

Image input data has 3 dimensions (rgb) per image and is then a list of images => has 4 dimensions.

Currently, passing such inputs generates the following error -

Traceback (most recent call last):
  File "/home/paula/documents/mastersproject/hierarchical-explainability/animal_dataset/train_with_hiclass.py", line 8, in <module>
    my_classifier.fit(X_train, y_train)
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/hiclass/LocalClassifierPerParentNode.py", line 100, in fit
    super()._pre_fit(X, y, sample_weight)
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/hiclass/HierarchicalClassifier.py", line 138, in _pre_fit
    self.X_, self.y_ = self._validate_data(
                       ^^^^^^^^^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/base.py", line 622, in _validate_data
    X, y = check_X_y(X, y, **check_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py", line 1146, in check_X_y
    X = check_array(
        ^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py", line 951, in check_array
    raise ValueError(
ValueError: Found array with dim 4. LocalClassifierPerParentNode expected <= 2.Traceback (most recent call last):
  File "/home/paula/documents/mastersproject/hierarchical-explainability/animal_dataset/train_with_hiclass.py", line 8, in <module>
    my_classifier.fit(X_train, y_train)
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/hiclass/LocalClassifierPerParentNode.py", line 100, in fit
    super()._pre_fit(X, y, sample_weight)
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/hiclass/HierarchicalClassifier.py", line 138, in _pre_fit
    self.X_, self.y_ = self._validate_data(
                       ^^^^^^^^^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/base.py", line 622, in _validate_data
    X, y = check_X_y(X, y, **check_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py", line 1146, in check_X_y
    X = check_array(
        ^^^^^^^^^^^^
  File "/home/paula/documents/mastersproject/hierarchical-explainability/.venv/lib/python3.11/site-packages/sklearn/utils/validation.py", line 951, in check_array
    raise ValueError(
ValueError: Found array with dim 4. LocalClassifierPerParentNode expected <= 2.

This solution simply supplies the parameter allow_nd=True in the fit pipeline and allow_nd=True, ensure_2d=False in the predict pipeline to ensure the support of multi dimensional inputs.

@iwan-tee
Copy link
Collaborator

iwan-tee commented Nov 22, 2023

your changes seem to be correct and be in a right way

@mirand863
Copy link
Collaborator

mirand863 commented Nov 22, 2023

Hi @ashishpatel16,

Thank you for the pull request! It looks good to me, but it is failing some linting tests. Can you please run black and commit again? It is also a good idea to setup the pre-commit according to the instructions in the contributing file.

@mirand863 mirand863 changed the title Add support for allowing multi-dimensional inputs (ndim > 2) Add support for allowing multi-dimensional inputs (ndim > 2) #minor Nov 22, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0f9f955) 98.40% compared to head (c2b1180) 98.40%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #97   +/-   ##
=======================================
  Coverage   98.40%   98.40%           
=======================================
  Files           8        8           
  Lines         566      566           
=======================================
  Hits          557      557           
  Misses          9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ashishpatel16
Copy link
Collaborator Author

@mirand863 The errors have been resolved finally, could you merge it if everything looks alright?

@mirand863 mirand863 merged commit 86a1296 into scikit-learn-contrib:main Nov 27, 2023
2 checks passed
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

Successfully merging this pull request may close these issues.

4 participants