Skip to content

252 feature implement orthogonal partial least squares opls algorithm#259

Open
paucablop wants to merge 41 commits intomainfrom
252-feature-implement-orthogonal-partial-least-squares-opls-algorithm
Open

252 feature implement orthogonal partial least squares opls algorithm#259
paucablop wants to merge 41 commits intomainfrom
252-feature-implement-orthogonal-partial-least-squares-opls-algorithm

Conversation

@paucablop
Copy link
Copy Markdown
Owner

@paucablop paucablop commented Apr 18, 2026

Summary

This pull request implements:

  • Orthogonal Partial Least Squares transformer
  • Direct Orthogonalization transformer
  • Adds retained and removed variance calculations for OSC transformers
  • Adds pull request template

Why is this change needed?

OPLS and DO are part of a family of filters commonly used in spectroscopic analysis

Closes

Related issues

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Documentation update
  • Tests only
  • CI / DevOps / tooling
  • Dependency update
  • Breaking change

What changed?

  • Imlpementation of OPLS
  • Implementation of DO
  • Calculation of variance ratios in OSC
  • Addition of PR Templates

What did NOT change?

  • These changes did not change the API

API and compatibility impact

  • No public API changes
  • Public API added
  • Public API changed
  • Deprecation introduced
  • Breaking change introduced

Notes

  • scikit-learn API compatibility: all confirmed
  • Affected modules/classes/functions: NA
  • Backward compatibility considerations: backwards compatible

Validation

  • task format-check
  • task lint
  • task spelling
  • task type-check
  • task test
  • task coverage
  • task test:matrix
  • task docs:check
  • task build

Validation notes

NA

Tests

  • Added new tests
  • Updated existing tests
  • No tests added because this PR only changes docs / CI / metadata

Test coverage details

  • Relevant test files: tests in projection/*
  • Numerical / estimator behavior checked: asserting on numerical analysis

Documentation

  • Docs updated
  • Docstrings updated
  • No docs update needed

Documentation notes

OSC, DO, EPO and OPLS docstrings were updated. OPLS and DO were added to the documentation page and are displayed.

Dependency / build / CI impact

  • No dependency changes
  • Runtime dependency change
  • Dev dependency change
  • GitHub Actions / CI changed
  • Build/release process changed

Notes

  • Ensure to have the latest version of ty=>0.0.30

Reviewer focus

Please focus on:

  • Correctness of the mathematical implementation

Checklist

  • I linked the relevant issue(s) or explained why none exists
  • I kept this PR scoped to a single purpose
  • I added or updated tests where appropriate
  • I updated documentation where appropriate
  • I verified the change locally using the relevant tasks above
  • I considered backward compatibility and public API impact
  • I am ready for review

@paucablop paucablop added this to the v1.0.0 milestone Apr 18, 2026
@paucablop paucablop self-assigned this Apr 18, 2026
@paucablop paucablop added the enhancement New feature or request label Apr 18, 2026
@NusretSalli
Copy link
Copy Markdown
Collaborator

NusretSalli commented Apr 18, 2026

Hi @paucablop!
So far it looks very good, but I am not done at all with the review 😄

I really like the level of documentation you provide which is always very good. Also like the PR template - I will definitely use that when I make PRs in the future.

As I said, I have not finished the review at all, but will hopefully finish it either tomorrow or early next week! 😄

@paucablop
Copy link
Copy Markdown
Owner Author

Hi @paucablop! So far it looks very good, but I am not done at all with the review 😄

I really like the level of documentation you provide which is always very good. Also like the PR template - I will definitely use that when I make PRs in the future.

As I said, I have not finished the review at all, but will hopefully finish it either tomorrow or early next week! 😄

Super!! No rush @NusretSalli take your time! 😄 And thanks a lot 🤩 🤩

@paucablop paucablop moved this to Review in CHEMOTOOLS Apr 19, 2026
Comment thread chemotools/projection/_orthogonal_pls.py
Comment on lines +104 to +108

_parameter_constraints: dict = {
"n_components": [Interval(Integral, 1, None, closed="left")],
"copy": ["boolean"],
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am wondering if there should be a check done for the number of components you can define so that n_components = min(n_samples, n_features). Otherwise users can ask for more components than the rank of X matrix, which results in Xk to be rank deficient.

Comment thread chemotools/projection/_orthogonal_pls.py Outdated
Comment thread chemotools/projection/_orthogonal_pls.py Outdated
total_ss_x_k = np.sum(Xk**2)

# Step 11: Calculate variance ratio in prediction matrix
self.retained_variance_ratio_ = total_ss_x_k / total_ss_x
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Even though this might be unlikely, it might be good to add a check to see if you are diving with 0. Essentially you can check if total_ss_x=0

Comment thread chemotools/projection/_orthogonal_pls.py Outdated
Comment on lines +165 to +167
yk = y_centered.copy()
yk = y_centered.reshape(-1, 1) if y_centered.ndim == 1 else y_centered

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The first yk call is getting overwritten by the next yk variable declaration, making the first call redundant

Comment thread chemotools/projection/_direct_orthogonalization.py Outdated
Comment on lines +202 to +206
# Step 7: Calculate sum of squares in defleated Xk
total_ss_x_k = np.sum(X_deflated**2)

# Step 8: Calculate variance ratio in prediction matrix
self.retained_variance_ratio_ = total_ss_x_k / total_ss_x
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same feedback as in _orthogonal_pls.py

paucablop and others added 4 commits April 26, 2026 15:55
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Nusret Emirhan Salli <110097112+NusretSalli@users.noreply.github.com>
Co-authored-by: Nusret Emirhan Salli <110097112+NusretSalli@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Review

Development

Successfully merging this pull request may close these issues.

feature: Implement Orthogonal Partial Least Squares (OPLS) algorithm

3 participants