-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
API Deprecate n_feature_ fitted attribute in PCA
#24421
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
API Deprecate n_feature_ fitted attribute in PCA
#24421
Conversation
n_feature_ fitted attribute in PCA
glemaitre
left a comment
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 error that you get in the CIs indicated to you that we don't make deprecation in this way. You should follow the following: https://scikit-learn.org/dev/developers/contributing.html#deprecation
Since we already introduce n_features_in_, we don't have to create a private attribute _n_features to raise the deprecation warning.
Indeed, you only need to add the following property:
# TODO(1.4): remove in 1.4
# mypy error: Decorated property not supported
@deprecated( # type: ignore
"Attribute `n_features_` was deprecated in version 1.2 and will be "
"removed in 1.4. Use `n_features_in_` instead."
)
@property
def n_features_(self):
return self.n_features_in_In addition, you need to add a test to check that we raise properly the warning:
def test_pca_n_features_deprecation():
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
pca = PCA(n_components=2).fit(X)
with pytest.warns(FutureWarning, match="`n_features_` was deprecated"):
pca.n_features_|
You can have a look at how it was done for the other estimators: https://github.com/scikit-learn/scikit-learn/pull/24388/files |
7c8f1ef to
740945b
Compare
|
Thank you @glemaitre for the hints and support. I have updated the PR with your inputs. My fault for not checking documentation for deprecation |
glemaitre
left a comment
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.
We can remove the setting for n_features_in_ since it should be done in the BaseEstimator class already.
58f89d9 to
57337ae
Compare
|
adapted the PR comments and rebased against main |
glemaitre
left a comment
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.
Thanks @Kshitij68 LGTM.
@jeremiedbb do you want to have a quick look at it?
jeremiedbb
left a comment
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.
LGTM. Thanks @Kshitij68
|
Thanks for reviews. |

Reference Issues/PRs
#24387
What does this implement/fix? Explain your changes.
As discussed in #24387 , n_features_ in favor of n_features_in
http://scikit-learn.org/dev/faq.html#why-is-my-pull-request-not-getting-any-attention.