Skip to content

More informative error when calling transform of unfitted metric learner #255

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

Closed
bellet opened this issue Oct 29, 2019 · 1 comment
Closed
Milestone

Comments

@bellet
Copy link
Member

bellet commented Oct 29, 2019

We should throw an informative error/exception when one attempts to use an unfitted transformer to transform data (or any other method which requires the metric learner to be fitted). See below what happens in metric-learn versus sklearn. We can probably borrow some code from sklearn to handle this similarly.

Example for metric-learn:

>>> from metric_learn import NCA
>>> from sklearn.datasets import make_classification
>>> X, y = make_classification()
>>> nca = NCA()
>>> nca.transform(X)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aurelien/Documents/research/github/metric-learn/metric_learn/base_metric.py", line 244, in transform
    preprocessor=self.preprocessor_,
AttributeError: 'NCA' object has no attribute 'preprocessor_'

Example for sklearn:

>>> from sklearn.decomposition import PCA
>>> from sklearn.datasets import make_classification
>>> X, y = make_classification()
>>> pca = PCA()
>>> pca.transform(X)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aurelien/anaconda3/lib/python3.7/site-packages/sklearn/decomposition/base.py", line 125, in transform
    check_is_fitted(self, ['mean_', 'components_'], all_or_any=all)
  File "/home/aurelien/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py", line 914, in check_is_fitted
    raise NotFittedError(msg % {'name': type(estimator).__name__})
sklearn.exceptions.NotFittedError: This PCA instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.
@bellet bellet changed the title More informative error when trying to transform before fit More informative error when trying to transform unfitted metric learner Oct 29, 2019
@bellet bellet changed the title More informative error when trying to transform unfitted metric learner More informative error when calling transform of unfitted metric learner Oct 29, 2019
@bellet bellet added this to the v0.6.0 milestone Oct 30, 2019
@bellet
Copy link
Member Author

bellet commented Dec 5, 2019

Done in #267

@bellet bellet closed this as completed Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant