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

Skip to content

FIX validate parameters in fit for FastICA - #21432

Merged
thomasjpfan merged 3 commits into
scikit-learn:mainfrom
hhnnhh:fastica
Oct 23, 2021
Merged

FIX validate parameters in fit for FastICA#21432
thomasjpfan merged 3 commits into
scikit-learn:mainfrom
hhnnhh:fastica

Conversation

@hhnnhh

@hhnnhh hhnnhh commented Oct 23, 2021

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Addresses #21406

What does this implement/fix? Explain your changes.

  1. Moves ValueError from init to _fit
  2. checks ValueError in test_fastica.py

Any other comments?

#DataUmbrella

@thomasjpfan thomasjpfan 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.

Small comment on the tests, otherwise LGTM

w_init = rng.randn(n_features + 1, n_features + 1)
with pytest.raises(ValueError, match="max_iter should be greater than 1"):
FastICA(max_iter=0)
FastICA(max_iter=0).fit(X)

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.

To make sure that fit is raised:

fastica = FastICA(max_iter=0)
with pytest.raises(ValueError, match="max_iter should be greater than 1"):
    fastica.fit(X)

@glemaitre glemaitre changed the title ENH Removes validation in __init__ for FastICA FIX validate parameters in fit for FastICA Oct 23, 2021
@glemaitre

Copy link
Copy Markdown
Member

I think that we should add an entry in the changelog since it could have an effect on third-party libraries.

Please add an entry to the change log at doc/whats_new/v1.1.rst. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:. For instance, it should look like:

- |Fix| :class:`decomposition.FastICA` nows validate input parameters in `fit`
  instead of `__init__`.
  :pr:`21432` by :user:`Hannah Bohle  <hhnnhh>`.

It should in the section:

:mod:`sklearn.decomposition`

@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.

This should solve the failures in the CI.

rng = np.random.RandomState(0)
X = rng.random_sample((n_samples, n_features))
w_init = rng.randn(n_features + 1, n_features + 1)
fastica = FastICA(max_iter=0)

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.

fastica is also the name of a function in scikit-learn:
https://scikit-learn.org/stable/modules/generated/fastica-function.html#sklearn.decomposition.fastica

So you need to rename to not have a clash of names:

Suggested change
fastica = FastICA(max_iter=0)
fastica_estimator = FastICA(max_iter=0)

fastica = FastICA(max_iter=0)
with pytest.raises(ValueError, match="max_iter should be greater than 1"):
FastICA(max_iter=0)
fastica.fit(X)

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.

Suggested change
fastica.fit(X)
fastica_estimator.fit(X)

@thomasjpfan thomasjpfan 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.

LGTM

@thomasjpfan
thomasjpfan merged commit 6f720c5 into scikit-learn:main Oct 23, 2021
ogrisel pushed a commit to ogrisel/scikit-learn that referenced this pull request Oct 28, 2021
samronsin pushed a commit to samronsin/scikit-learn that referenced this pull request Nov 30, 2021
@hhnnhh
hhnnhh deleted the fastica branch December 17, 2021 13:13
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.

6 participants