Skip to content

[MRG] Dynamically set n_quantiles to min(n_samples, n_quantiles) in QuantileTransformer - #13333

Merged
jnothman merged 9 commits into
scikit-learn:masterfrom
albertcthomas:n_quantiles
Mar 1, 2019
Merged

jnothman merged 9 commits into
scikit-learn:masterfrom
albertcthomas:n_quantiles

Conversation

@albertcthomas

Copy link
Copy Markdown
Contributor

Fixes #13315

Values of n_quantiles larger than n_samples either do not lead to a better approximation of the cdf estimator or to a wrong approximation. See #13315 for details.

Don't know if this is considered as a bug or if this requires a deprecation cycle?

@glemaitre glemaitre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need an entry in what's new. If we considered it as a bug fix then we don't need a deprecation.

Comment thread sklearn/preprocessing/data.py Resolved
transformer.transform, 10)
# check that a warning is raised is n_quantiles > n_samples
transformer = QuantileTransformer(n_quantiles=100)
assert_warns_message(UserWarning,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you use pytest to catch warning instead?

Comment thread sklearn/preprocessing/data.py Outdated
n_samples = X.shape[0]

if self.n_quantiles > n_samples:
self.n_quantiles = n_samples

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should be called n_quantiles_ isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes indeed I just fixed it

@glemaitre
glemaitre self-requested a review February 28, 2019 16:28
@albertcthomas

Copy link
Copy Markdown
Contributor Author

Thanks @glemaitre

n_samples = X.shape[0]

if self.n_quantiles > n_samples:
warnings.warn("n_quantiles (%s) is greater than the total number "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is more verbose than is helpful. "n_quantiles (%d) is being reduced to the number of samples (%d)" if you want to add another phrase explaining why, okay, but I think it's intuitively okay.

@jnothman jnothman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

otherwise LGTM

@albertcthomas

Copy link
Copy Markdown
Contributor Author

Thanks @jnothman

@jnothman
jnothman merged commit 2ad8735 into scikit-learn:master Mar 1, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
xhluca pushed a commit to xhluca/scikit-learn that referenced this pull request Apr 28, 2019
koenvandevelde pushed a commit to koenvandevelde/scikit-learn that referenced this pull request Jul 12, 2019
davidgegiya added a commit to davidgegiya/agent-orchestrator that referenced this pull request Nov 9, 2026
…ansformer

Pin 04a5733b86bba57a48520b97b9c0a5cd325a1b9a and its regression selectors for reproducible runs.

Source: scikit-learn/scikit-learn#13333
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants