Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Kshitij68
Copy link
Contributor

@Kshitij68 Kshitij68 commented Sep 12, 2022

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.

@Kshitij68
Copy link
Contributor Author

Screenshot from local documentation built.


Screenshot 2022-09-12 at 5 14 23 AM

@glemaitre glemaitre changed the title Depreciate n_features_ attribute for PCA #24387 API Deprecate n_feature_ fitted attribute in PCA Sep 12, 2022
Copy link
Member

@glemaitre glemaitre left a 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_

@glemaitre
Copy link
Member

You can have a look at how it was done for the other estimators: https://github.com/scikit-learn/scikit-learn/pull/24388/files

@Kshitij68 Kshitij68 force-pushed the Depreciate-n_features-in-PCA branch from 7c8f1ef to 740945b Compare September 12, 2022 10:15
@Kshitij68
Copy link
Contributor Author

Thank you @glemaitre for the hints and support. I have updated the PR with your inputs.

My fault for not checking documentation for deprecation

Copy link
Member

@glemaitre glemaitre left a 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.

@Kshitij68 Kshitij68 force-pushed the Depreciate-n_features-in-PCA branch from 58f89d9 to 57337ae Compare September 13, 2022 02:00
@Kshitij68
Copy link
Contributor Author

adapted the PR comments and rebased against main

Copy link
Member

@glemaitre glemaitre left a 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?

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @Kshitij68

@jeremiedbb jeremiedbb merged commit 2c2ee2d into scikit-learn:main Sep 13, 2022
@Kshitij68
Copy link
Contributor Author

Thanks for reviews.
Excited to have my name on a changelog of such a popular repo πŸ‘―β€β™‚οΈ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants