-
Notifications
You must be signed in to change notification settings - Fork 532
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
[REVIEW] 018 add unfitted error pca & tests on IPCA #3272
Merged
dantegd
merged 8 commits into
rapidsai:branch-0.18
from
lowener:018_add_unfitted_error_pca
Dec 17, 2020
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
96e783d
Adding NotFittedError to PCA
lowener 5ee8b76
Fixed typo in PCA import
lowener a04502a
Fixed check_is_fitted call
lowener f48fa3c
Fixed missing parenthesis
lowener 568c164
Added test on svd_flip
lowener 1cb6759
fix style ipca
lowener 81b4536
Fixed whitespace style
lowener 8ddd2a9
Removed useless test
lowener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ from cuml.common.array_descriptor import CumlArrayDescriptor | |
from cuml.common import using_output_type | ||
from cuml.prims.stats import cov | ||
from cuml.common.input_utils import sparse_scipy_to_cp | ||
from cuml.common.exceptions import NotFittedError | ||
|
||
|
||
cdef extern from "cuml/decomposition/pca.hpp" namespace "ML": | ||
|
@@ -554,6 +555,7 @@ class PCA(Base): | |
|
||
""" | ||
|
||
self._check_is_fitted('components_') | ||
if cupyx.scipy.sparse.issparse(X): | ||
return self._sparse_inverse_transform(X, | ||
return_sparse=return_sparse, | ||
|
@@ -653,6 +655,7 @@ class PCA(Base): | |
|
||
""" | ||
|
||
self._check_is_fitted('components_') | ||
if cupyx.scipy.sparse.issparse(X): | ||
return self._sparse_transform(X) | ||
elif scipy.sparse.issparse(X): | ||
|
@@ -736,3 +739,9 @@ class PCA(Base): | |
'X_types_gpu': ['2darray', 'sparse'], | ||
'X_types': ['2darray', 'sparse'] | ||
} | ||
|
||
def _check_is_fitted(self, attr): | ||
lowener marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not hasattr(self, attr) or (getattr(self, attr) is None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, agreed on the generalization - good suggestion from Dante There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do the generalization of |
||
msg = ("This instance is not fitted yet. Call 'fit' " | ||
"with appropriate arguments before using this estimator.") | ||
raise NotFittedError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that in sklearn, they do
sklearn.utils.validation.check_is_fitted
in a similar way. Is there an advantage to having this as a method on base instead of a utility? I believe we can always add the function later as a wrapper if necessary, so probably not a major issue either way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advantage of a base method would be that there is no additionnal import needed, and it would be really easy to use. But then we would have two copy of this code, for the estimators with Dask.