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

Skip to content

FIX add n_targets allowing consistent shape prediction before calling fit in GPR - #23099

Merged
glemaitre merged 26 commits into
scikit-learn:mainfrom
MaxwellLZH:fix/gpr-n-targets
May 31, 2023
Merged

FIX add n_targets allowing consistent shape prediction before calling fit in GPR#23099
glemaitre merged 26 commits into
scikit-learn:mainfrom
MaxwellLZH:fix/gpr-n-targets

Conversation

@MaxwellLZH

@MaxwellLZH MaxwellLZH commented Apr 10, 2022

Copy link
Copy Markdown
Contributor

Fixes #22430

Reference Issues/PRs

This PR adds a new argument n_targets for GaussianProcessRegressor as suggested in issue #22430 , which will be used to determine the output shape of both predict and sample_y, so the shape will be consistent before and after calling fit method.

Any other comments?

I'm not sure if we should raise error during the fit process if the dimension ofy does not match n_targets, since once we fit the model the output shape will be determined by the shape of y.

@MaxwellLZH

MaxwellLZH commented Apr 22, 2022

Copy link
Copy Markdown
Contributor Author

Hi @glemaitre, could you help take a look at this PR, thank you

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

It looks good. Could you add a what's new entry in 1.2.
Note that this is a bug fix rather than a feature.

Comment thread sklearn/gaussian_process/_gpr.py Outdated
Comment thread sklearn/gaussian_process/_gpr.py Outdated
Comment thread sklearn/gaussian_process/_gpr.py Outdated
Comment thread sklearn/gaussian_process/_gpr.py Outdated
Comment thread sklearn/gaussian_process/tests/test_gpr.py
Comment thread sklearn/gaussian_process/tests/test_gpr.py Outdated
Comment thread sklearn/gaussian_process/tests/test_gpr.py Outdated
Comment thread sklearn/gaussian_process/tests/test_gpr.py Outdated
Comment thread sklearn/gaussian_process/tests/test_gpr.py Outdated
Comment thread sklearn/gaussian_process/tests/test_gpr.py Outdated
@glemaitre glemaitre changed the title FET add argument n_targets for GPR FIX add n_targets allowing consistent shape prediction before calling fit in GPR Jun 22, 2022
MaxwellLZH and others added 15 commits June 23, 2022 22:04
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>
@MaxwellLZH
MaxwellLZH requested a review from glemaitre June 24, 2022 01:39

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

LGTM

@glemaitre glemaitre added this to the 1.3 milestone Jan 11, 2023
@glemaitre glemaitre added the Waiting for Second Reviewer First reviewer is done, need a second one! label Jan 11, 2023
Comment thread sklearn/gaussian_process/_gpr.py

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

Thanks for the PR @MaxwellLZH. I directly pushed the remaining requested change. LGTM.

@jeremiedbb

Copy link
Copy Markdown
Member

@thomasjpfan are you happy with the latest updates ?

Comment thread sklearn/gaussian_process/_gpr.py Outdated
n_targets_seen = y.shape[1] if y.ndim > 1 else 1
if self.n_targets is not None and n_targets_seen != self.n_targets:
raise ValueError(
"Number of targets seen != n_targets. "

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 would favor a more literal error:

The number of targets seen in `y` is different from the parameter `n_targets`.
Got ...

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

Still my +1 on this one. Just a nitpick regarding the error message raised.

@glemaitre
glemaitre merged commit c8f79e2 into scikit-learn:main May 31, 2023
@glemaitre

Copy link
Copy Markdown
Member

LGTM. Merging since the changes requested by @thomasjpfan have been implemented.

REDVM pushed a commit to REDVM/scikit-learn that referenced this pull request Nov 16, 2023
…ng `fit` in GPR (scikit-learn#23099)

Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Jérémie du Boisberranger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:gaussian_process Waiting for Second Reviewer First reviewer is done, need a second one!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPR sample_y enforce n_targets=1 before calling fit

4 participants