Skip to content

API Adds feature_names_in_ to kernel_approximation #20841

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions sklearn/kernel_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class PolynomialCountSketch(BaseEstimator, TransformerMixin):

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Defined only when `X`
has feature names that are all strings.

.. versionadded:: 1.0

See Also
--------
AdditiveChi2Sampler : Approximate feature map for additive chi2 kernel.
Expand Down Expand Up @@ -256,6 +262,12 @@ class RBFSampler(TransformerMixin, BaseEstimator):

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Defined only when `X`
has feature names that are all strings.

.. versionadded:: 1.0

See Also
--------
AdditiveChi2Sampler : Approximate feature map for additive chi2 kernel.
Expand Down Expand Up @@ -386,6 +398,12 @@ class SkewedChi2Sampler(TransformerMixin, BaseEstimator):

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Defined only when `X`
has feature names that are all strings.

.. versionadded:: 1.0

See Also
--------
AdditiveChi2Sampler : Approximate feature map for additive chi2 kernel.
Expand Down Expand Up @@ -520,6 +538,12 @@ class AdditiveChi2Sampler(TransformerMixin, BaseEstimator):

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Defined only when `X`
has feature names that are all strings.

.. versionadded:: 1.0

See Also
--------
SkewedChi2Sampler : A Fourier-approximation to a non-additive variant of
Expand Down Expand Up @@ -764,6 +788,12 @@ class Nystroem(TransformerMixin, BaseEstimator):

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Defined only when `X`
has feature names that are all strings.

.. versionadded:: 1.0

See Also
--------
AdditiveChi2Sampler : Approximate feature map for additive chi2 kernel.
Expand Down
1 change: 0 additions & 1 deletion sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ def test_check_n_features_in_after_fitting(estimator):
"compose",
"ensemble",
"feature_extraction",
"kernel_approximation",
"model_selection",
"multiclass",
"multioutput",
Expand Down
3 changes: 3 additions & 0 deletions sklearn/utils/estimator_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3722,6 +3722,9 @@ def check_dataframe_column_names_consistency(name, estimator_orig):
set_random_state(estimator)

X_orig = rng.normal(size=(150, 8))

# Some picky estimators (e.g. SkewedChi2Sampler) only accept skewed positive data.
X_orig -= X_orig.min() + 0.5
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this because the original fails for SkewedChi2Sampler.transform with skewedness=1.0:

if (X <= -self.skewedness).any():
raise ValueError("X may not contain entries smaller than -skewedness.")

Copy link
Member

Choose a reason for hiding this comment

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

I stumbled upon the same issue when trying to tackle this module. I am fine with your solution because I could not find a better idea...

Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment for that line? And maybe use X_orig += X_orig.abs().max() + 0.5 to be sure it's positive.

Copy link
Member

Choose a reason for hiding this comment

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

I added a comment. I left the -= .min() pattern because it is used several times elsewhere in the test file.

X_orig = _enforce_estimator_tags_x(estimator, X_orig)
X_orig = _pairwise_estimator_convert_X(X_orig, estimator)
n_samples, n_features = X_orig.shape
Expand Down