-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
MAINT Parameters validation for fastica
#24924
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
Conversation
f5097d5
to
087ff57
Compare
087ff57
to
d4e1bc7
Compare
sklearn/decomposition/_fastica.py
Outdated
"X": ["array-like"], | ||
"n_components": [Interval(Integral, 1, None, closed="left"), None], | ||
"algorithm": [StrOptions({"parallel", "deflation"})], | ||
"whiten": [ | ||
Hidden(StrOptions({"warn"})), | ||
StrOptions({"arbitrary-variance", "unit-variance"}), | ||
"boolean", | ||
], | ||
"fun": [StrOptions({"logcosh", "exp", "cube"}), callable], | ||
"fun_args": [dict, None], | ||
"max_iter": [Interval(Integral, 1, None, closed="left")], | ||
"tol": [Interval(Real, 0.0, None, closed="left")], | ||
"w_init": ["array-like", None], | ||
"whiten_solver": [StrOptions({"eigh", "svd"})], | ||
"random_state": ["random_state"], |
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.
All those parameters will be checked by the class FastICA
. So no need to check them. It will be enough to verify the 3 remaining parameters.
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.
So what about X? Leaving out X, makes test_function_param_validation
fail because of this I guess. Is it a good idea to give X a "no_validation"
?
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.
It will be validated when calling fit
or fit_transform
, I guess.
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.
I assume that it will test every variable in the signature. I am wondering if we should make a partial check if possible.
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.
Is partial validation possible?
My two first initial solutions are either bypassing X validation with "no_validation"
constraint (but I don't know if it is for this purpose) or giving X proper validation ("X": ["array-like"]
).
What's your suggestion?
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.
You mean double-validate every parameter or just X?
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.
Every parameter indeed.
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.
It is unfortunate that our validation framework does not allow for partial validation. Moving forward we would need to keep the constraints in sync between the function and the estimator. For this specific PR, the fastica
function can call FastICA()._validate_params
to validate the common parameters and fastica
itself can validate the remaining ones: (X
and compute_sources
).
@jeremiedbb What do you think of adding a allow_partial_validation
flag to validate_params
?
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.
So I guess I should wait for the partial validations as it seems that the current tests does not allow it 🤔
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.
So I guess I should wait for the partial validations as it seems that the current tests does not allow it
@kianelbo To clarify, this PR did not need to be updated, because our tests does not allow for partial validation. I am okay with reverting 6cc6c77
(#24924) and having the double validation for now.
I opened #25058 to track the discussion.
I agree with you: we should use the class |
So we should have something like: est = FastICA(
n_components=n_components,
algorithm=algorithm,
whiten=whiten,
fun=fun,
fun_args=fun_args,
max_iter=max_iter,
tol=tol,
w_init=w_init,
whiten_solver=whiten_solver,
random_state=random_state,
)
if compute_sources:
S = est.fit_transform(X)
else:
est.fit(X)
S = None |
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 @kianelbo
This reverts commit 6cc6c77.
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 @kianelbo
Co-authored-by: jeremiedbb <jeremiedbb@yahoo.fr>
Co-authored-by: jeremiedbb <jeremiedbb@yahoo.fr>
Co-authored-by: jeremiedbb <jeremiedbb@yahoo.fr>
Reference Issues/PRs
Towards #24862
What does this implement/fix? Explain your changes.
Added param validation for
sklearn.decomposition.fastica
Any other comments?
The function calls the FastICA class but the validations are not performed since
_fit_transform
is called. What about using the class validation?