Skip to content

[DOC] Add PyTorch / Skorch example#704

Open
GrituX wants to merge 13 commits into
683-doc-example-gallery-rework-real-life-cases-high-dimensionalfrom
664-doc-include-dl-example-with-pytorch-and-skorch
Open

[DOC] Add PyTorch / Skorch example#704
GrituX wants to merge 13 commits into
683-doc-example-gallery-rework-real-life-cases-high-dimensionalfrom
664-doc-include-dl-example-with-pytorch-and-skorch

Conversation

@GrituX

@GrituX GrituX commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

I added an example to compute feature importance on pixels for binary classification on the MNIST digit dataset with a CNN estimator written in PyTorch and that interfaces with Scikit-Learn through the Skorch library.
The version limitation of Torch and Skorch come from Skorch as the support of __sklearn_is_fitted__ for estimators only arrived on 1.3 and 1.3.1 adds the support of sklearn v1.8 and 1.9.

@bthirion bthirion left a comment

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.

Thx ! Please find a few comments enclosed

Comment thread examples/plot_advanced_skorch.py Outdated
PyTorch models might not be used directly with HiDimStat for that reason.
However, with the help of a third party library `Skorch <https://skorch.readthedocs.io/en/stable/>`,
PyTorch can be interfaced with HiDimStat, and provide all of its functionalities.
In this example, we show how to define a Convolutional Neural Network (CNN) in Skorch,

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.

Suggested change
In this example, we show how to define a Convolutional Neural Network (CNN) in Skorch,
In this example, we define a Convolutional Neural Network (CNN) in Skorch,

Comment thread examples/plot_advanced_skorch.py Outdated
"""

# %%
# Deefining a PyTorch model

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.

Suggested change
# Deefining a PyTorch model
# Defining a PyTorch model

Comment thread examples/plot_advanced_skorch.py Outdated
# composed of 2 series of (Convolution, Activation, Pooling) layers,
# followed by 2 fully-connected layers.

import torch

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.

needed ?

Comment thread examples/plot_advanced_skorch.py Outdated
# %%
# Running HiDimStat feature importance computation
# ------------------------------------------------
# We cluster pixels through feature agglomeration, and define its connectivity

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.

Suggested change
# We cluster pixels through feature agglomeration, and define its connectivity
# We cluster pixels through feature agglomeration, while leveraging their grid structure

Comment thread examples/plot_advanced_skorch.py Outdated
# features_groups = {idx: [cluster_label] for idx, cluster_label in enumerate(clustering.labels_)}

# Careful when using Skorch, having n_jobs > 1 might create joblib and pickle issues.
pfi = PFI(

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.

Why not CFI instead ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CFI works too, it's just slower than PFI and requires more samples (2000 against 500) otherwise the solver often stumbles on situations where only 1 class is present in the data. But the runtime is still fine, so I made the switch.

GrituX and others added 5 commits July 3, 2026 10:17
* [ENH] initial implementation of LOCI.

* Changed importance measure, and fixed predict_one_features_group according to failing test.

* added multilabel case handling

* raised fdr threshold for less agressive power testing.

* Implemented multiclass test, and fixed LOCI multiclass code.

* Baseline mean of y is now taken on the train set. Reduced sample and feature size for tests.

---------

Co-authored-by: jpaillard <joseph.paillard@inria.fr>
@GrituX

GrituX commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Since this PR doesn't target the main branch, the CI will never be run ... So to see the result, this would need to be merged into the target branch, which this time targets main ...

@GrituX GrituX requested a review from bthirion July 6, 2026 13:24
@bthirion

Copy link
Copy Markdown
Collaborator

Where can one see the generated doc ?

@bthirion bthirion left a comment

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.

LGTM overall, just beware LOCI code that seems unrelated + I'd need to see the generatde doc: how does it render ? Can/should we shorted it a little bit ?

@@ -0,0 +1,253 @@
from functools import partial

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.

this is unrelated, right ?

@@ -0,0 +1,361 @@
import numpy as np

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.

this is unrelated, right ?

# Finally, we visualize the significant pixels identified by CFI for each of the
# classification tasks.

import matplotlib.pyplot as plt

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.

already imported

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