Skip to content

Fix predictions with missing y values - #15

Open
LaurianeJD wants to merge 2 commits into
johnsonandjohnson:mainfrom
LaurianeJD:fix_predict_missing_y
Open

LaurianeJD wants to merge 2 commits into
johnsonandjohnson:mainfrom
LaurianeJD:fix_predict_missing_y

Conversation

@LaurianeJD

Copy link
Copy Markdown

Purpose

Fix NipalsPLS.predict() when y has missing values, as discussed in #14 (see comment there for more details).

Background

The fit deflates y with T Qᵀ, but predict() returned T diag(b) Qᵀ. The inner coefficients b are exactly 1 for complete y, but not when y has missing values, where predict() then doesn't reproduce the fitted y, even on the training data.

Changes

  • predict(): Ŷ = T Qᵀ, without regression_matrix (b term)
  • get_reg_vector(): same, without regression_matrix
  • New test test_predict_with_missing_y(): fails on main, passes with the fix

The test uses a small random example rather than existing test data: YData.csv has a single complete y column (b = 1). A second target built from the spectra with missing values (as in #14) shows the problem only weakly (b ≈ 1.0004), while this random example shows it clearly (b = 3.4).

Results with complete y are unchanged.

Caveat

Overlaps with #14: both PRs change get_reg_vector(), and this fix also covers #14's set_components() growth fix with missing y. See my comment there.

@nielsschlusser @arden13

@nielsschlusser nielsschlusser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me in general!
One minor question with regards to the test, otherwise good to merge from my side.
Let's wait for PR #14 , though.

Comment thread tests/test_nipalsPLS_RandomGen.py

@nielsschlusser nielsschlusser left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me now. Thanks for your contribution!
Please wait with merging until the merge of PR #14 .

@LaurianeJD

Copy link
Copy Markdown
Author

@nielsschlusser Sure! After PR #14 is merged, I'll also add here the remaining necessary changes that I listed in #14 (comment) to make sure everything is consistent :)

@nielsschlusser

nielsschlusser commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Hey @LaurianeJD

I just had another thought: Shall we try to tighten the limits for the prediction unittest? I'd imagine the accuracy on the incomplete datasets should be increased. What do you think?

@LaurianeJD

LaurianeJD commented Oct 21, 2026 •

Copy link
Copy Markdown
Author

@nielsschlusser As far as I understood, test_fit_y isn't affected by my PR: the incomplete datasets used in that test have missing values in the features X, not in the target y. Since for that case y is complete, b=1 exactly, and the predictions are identical with and without the fix of this PR.
Or am I misunderstanding what you were mentioning?

This branch has not been deployed

No deployments
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.

2 participants