vcnet.classifiers

Classifier models for VCNet.

A VCNet architecture is made of a counterfactual generator and a classifier. This module implements the classes that define the classifiers of the architecture.

Two classes are provided:

  • Classifier: the implementation of a default classifier architecture for the joint model of VCNet. It is implemented as a Lightning module. The same architecture can be used in a post-hoc model.

  • SKLearnClassifier: a wrapper for a shallow classifier to be explained with a post-hoc model.

Note

You can define your own classifier by inheriting from one of these two classes.

Warning

SKLearnClassifier cannot be used in a joint-learning fashion.

class vcnet.classifiers.SKLearnClassifier(hp)[source]

Bases: object

Wrapper to use a sklearn classifier in the VCNet pipeline.

Parameters:

hp (Dict) – configuration of the classifier (hyperparameters) and of the dataset

Example of minimal configuration

Example of a minimal dictionary to set up a SKLearnClassifier in VCNet.

hp = {
    "dataset": {
        "target":"income",
    },
    "classifier_params" : {
        "skname":  "RandomForestClassifier",
        "kwargs": {
            "n_estimators" : 50,
        }
    }
}
classifier = SKLearnClassifier(hp)
classifier.fit(dataset.df_train)

Note

This class can also be used with an XGBoost classifier (skname set to “XGBClassifier”).

Note

We refer the user to the sklearn API for the list of the classifier parameters. When using XGBoost, the parameters are described in the XGBoost API.

fit(X: pandas.DataFrame)[source]

Fits the model.

Parameters:

X (pd.DataFrame) – dataset on which the model is trained (including the target attribute)

class vcnet.classifiers.Classifier(*args: Any, **kwargs: Any)[source]

Bases: LightningModule

Simple fully connected classifier that is used by default for the classification of numerical tabular data.

The network architecture is made of three hidden fully connected layers and an output layer, with ReLU activation functions between layers and a sigmoid at the end.

The sizes of the layers are defined in the hyperparameters provided when the model is instantiated.

The mandatory parameters to define in the dictionary are:

  • the input size (in dataset > feature_size)

  • the layer sizes (in classifier_params: l1_size, l2_size and l3_size)

  • the output size (in dataset > class_size)

The learning rate (defined by lr in classifier_params) is also recommended. Its default value is 0.01.

Parameters:

hp (Dict) – configuration of the classifier (hyperparameters) and of the dataset.

Raises:

KeyError – if the settings do not contain all the required parameters

forward(x: torch.tensor) → torch.tensor[source]

Applies the classification model to the input x.

Parameters:

x (torch.tensor) – tensor of examples to classify.

Returns:

the probabilistic classification vector

Return type:

torch.tensor

training_step(batch, batch_idx) → float[source]

Implementation of a training step.

configure_optimizers()[source]