Skip to content

Conversation

Genuster
Copy link
Contributor

@Genuster Genuster commented Aug 6, 2025

Fixes, internal improvements and a subtle API change for LinearModel.

  • make LinearModel proper metaestimator, i.e. self.model should first be cloned to model_ and only then fitted
  • set proper sklearn tags
  • make LinearModel work with OneVsRestClassifier metaestimator
  • explicitly validate that the model is either classifier or regressor
  • cover missing tests

@larsoner
Copy link
Member

larsoner commented Aug 7, 2025

Let me know when I should look!

One comment -- I see a commit message make validation compatible with sklearn<1.6... I would say it's not a big priority. I think it's okay in our test_*_compliance functions to require a fairly recent sklearn (more recent than our minimum supported version) because they probably improve and fix compliance tests over time (and even improve/fix their data validation function we use internally). You can do a pytest.importorskip("sklearn", "1.6") inside the test if you want. But if it doesn't require much work to make the _compliance tests work on older sklearn then feel free to keep working on it.

@Genuster
Copy link
Contributor Author

Genuster commented Aug 7, 2025

Thanks @larsoner, it's more complicated than the _compliance tests. LinearModel would be unusable for users with lower sklearn version because of the __sklearn__tags() call for other classes for parameter validation. But if it's ok to expect sklearn 1.6 for the next MNE versions, then I'll absolutely follow your pytest.importorskip("sklearn", "1.6"), because I can't seem to properly fix this whole thing for the older ubuntu tests. So I'm not sure how to handle this actually.

Let me know when I should look!

Apart from this issue, it's pretty much ready for the review! (btw, the spatial filter visualisation PR is also ready😀)

@larsoner
Copy link
Member

larsoner commented Aug 7, 2025

LinearModel would be unusable for users with lower sklearn version because of the __sklearn__tags() call for other classes for parameter validation

I don't quite follow... I think __sklearn_tags__ was introduced in 1.6 (right?) so any sklearn version before that should just completely ignore / not use the method. So whatever gymnastics you're doing for those shouldn't affect someone running, say, 1.5 or 1.4. (Our min supported for the next MNE release looks like it'll be 1.3 FYI), right?

@Genuster
Copy link
Contributor Author

Genuster commented Aug 7, 2025

So whatever gymnastics you're doing for those

😁 I was calling __sklearn_tags__ in _validate_params method, which in turn is calling super().__sklearn_tags__ and self.model.__sklearn_tags__ and this would cause errors in old sklearns.
But I changed it now to explicit is_regressor, is_classifier, let's see if can I make these work.

@larsoner
Copy link
Member

larsoner commented Aug 7, 2025

Ahh I see... yeah maybe better to avoid calling __sklearn_tags__ internally if possible

@Genuster Genuster marked this pull request as ready for review August 8, 2025 20:41
@Genuster Genuster requested a review from jasmainak as a code owner August 8, 2025 20:41
@Genuster Genuster changed the title WIP: Refactor LinearModel API: Refactor LinearModel Aug 8, 2025
@Genuster Genuster changed the title API: Refactor LinearModel BUG: Refactor LinearModel Aug 11, 2025
@larsoner
Copy link
Member

@Genuster should I look and merge? FYI we don't get notified for commits or anything so it's a good idea to re-ping for review once you've addressed comments!

@larsoner
Copy link
Member

... can you push a commit with [circle full] so we can make sure all examples work? You can use for example

git commit --allow-empty -m 'TST: All examples [circle full]'

Once that's done, LGTM and I think we can merge assuming all examples pass!

@Genuster
Copy link
Contributor Author

@larsoner yes, it's ready! Will ping you next time :)

@larsoner larsoner enabled auto-merge (squash) August 18, 2025 13:33
@larsoner larsoner merged commit f7cab3a into mne-tools:main Aug 18, 2025
34 of 42 checks passed
@Genuster Genuster deleted the linearmodel branch August 20, 2025 15:48
zEdS15B3GCwq pushed a commit to zEdS15B3GCwq/mne-python that referenced this pull request Aug 25, 2025
@Genuster Genuster mentioned this pull request Aug 25, 2025
7 tasks
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