scikit-adaptation / skada

Domain adaptation toolbox compatible with scikit-learn and pytorch
https://scikit-adaptation.github.io/
BSD 3-Clause "New" or "Revised" License
56 stars 16 forks source link

Bug when using a da_pipeline inside a da_pipeline (I know) #98

Closed rflamary closed 5 months ago

rflamary commented 5 months ago

When running this simple code that should run (basically using CORAL that is itself a DA pipeline)

from skada import make_da_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC

# create a DA pipeline
pipe = make_da_pipeline(StandardScaler(),CORAL(base_estimator=SVC()))
pipe.fit(X, y, sample_domain=sample_domain)

we have the following error

AttributeError                            Traceback (most recent call last)
[~/PYTHON/skada/examples/plot_how_to_use_skada.py](https://file+.vscode-resource.vscode-cdn.net/home/rflamary/PYTHON/skada/~/PYTHON/skada/examples/plot_how_to_use_skada.py) in <cell line: 15>()
     13 # create a DA pipeline
     14 pipe = make_da_pipeline(StandardScaler(),CORAL(base_estimator=SVC()))
---> 15 pipe.fit(X, y, sample_domain=sample_domain)
     16 
     17 print('Accuracy on target:',pipe.score(Xt,yt))

[~/.local/lib/python3.10/site-packages/sklearn/base.py](https://file+.vscode-resource.vscode-cdn.net/home/rflamary/PYTHON/skada/~/.local/lib/python3.10/site-packages/sklearn/base.py) in wrapper(estimator, *args, **kwargs)
   1192                 )
   1193             ):
-> 1194                 return fit_method(estimator, *args, **kwargs)
   1195 
   1196         return wrapper

[~/.local/lib/python3.10/site-packages/sklearn/pipeline.py](https://file+.vscode-resource.vscode-cdn.net/home/rflamary/PYTHON/skada/~/.local/lib/python3.10/site-packages/sklearn/pipeline.py) in fit(self, X, y, **params)
    467             Pipeline with fitted steps.
    468         """
--> 469         routed_params = self._check_method_params(method="fit", props=params)
    470         Xt = self._fit(X, y, routed_params)
    471         with _print_elapsed_time("Pipeline", self._log_message(len(self.steps) - 1)):

[~/.local/lib/python3.10/site-packages/sklearn/pipeline.py](https://file+.vscode-resource.vscode-cdn.net/home/rflamary/PYTHON/skada/~/.local/lib/python3.10/site-packages/sklearn/pipeline.py) in _check_method_params(self, method, props, **kwargs)
    353     def _check_method_params(self, method, props, **kwargs):
...
--> 165         request.fit.add_request(param='sample_domain', alias=True)
    166         request.transform.add_request(param='sample_domain', alias=True)
    167         request.predict.add_request(param='sample_domain', alias=True)

AttributeError: 'MetadataRouter' object has no attribute 'fit'

interestingly the code above works for a classical sklearn make_pipeline but not ours.