[DOC] Add PyTorch / Skorch example#704
Conversation
…computation time.
bthirion
left a comment
There was a problem hiding this comment.
Thx ! Please find a few comments enclosed
| 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, |
There was a problem hiding this comment.
| 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, |
| """ | ||
|
|
||
| # %% | ||
| # Deefining a PyTorch model |
There was a problem hiding this comment.
| # Deefining a PyTorch model | |
| # Defining a PyTorch model |
| # composed of 2 series of (Convolution, Activation, Pooling) layers, | ||
| # followed by 2 fully-connected layers. | ||
|
|
||
| import torch |
| # %% | ||
| # Running HiDimStat feature importance computation | ||
| # ------------------------------------------------ | ||
| # We cluster pixels through feature agglomeration, and define its connectivity |
There was a problem hiding this comment.
| # We cluster pixels through feature agglomeration, and define its connectivity | |
| # We cluster pixels through feature agglomeration, while leveraging their grid structure |
| # 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( |
There was a problem hiding this comment.
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.
* [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>
|
Since this PR doesn't target the |
|
Where can one see the generated doc ? |
bthirion
left a comment
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
this is unrelated, right ?
| @@ -0,0 +1,361 @@ | |||
| import numpy as np | |||
There was a problem hiding this comment.
this is unrelated, right ?
| # Finally, we visualize the significant pixels identified by CFI for each of the | ||
| # classification tasks. | ||
|
|
||
| import matplotlib.pyplot as plt |
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.