Feature Attribution

confetti.attribution.cam.cam(model, X_data: ndarray)

Compute Class Activation Maps (CAMs) [1]. for 1D convolutional classifiers.

This function computes class activation maps for a trained Keras model by combining the activations of the final Conv1D layer with the weights of the final Dense classifier layer. It highlights the temporal regions most influential for the model’s predicted class.

Parameters:
  • model (keras.Model) – A trained Keras model containing at least one Conv1D layer followed by a Dense classification layer.

  • X_data (ndarray of shape (n_samples, timesteps, channels)) – Input multivariate time series for which CAMs will be computed.

Returns:

The class activation map for each input instance.

Return type:

ndarray of shape (n_samples, timesteps)

Raises:

CONFETTIConfigurationError – If no Conv1D layer is found, if no Dense output layer is present, or if the number of filters in the final convolutional layer does not match the input dimensionality of the classifier layer.

Note

The CAM for a given instance is defined as:

CAM(t) = Σ_k w[k, c] * A[k, t]
where:
  • A[k, t] is the activation of filter k at timestep t from the final convolutional layer.

  • w[:, c] are the weights connecting each filter to the predicted class c in the final dense layer.

References

confetti.attribution.cam_visualization.visualize_cam(weights: ndarray, instance_index: int) None

Visualize the Class Activation Map (CAM) for a single instance.

This function produces a simple matplotlib plot showing the normalized class activation map for a chosen instance. The weights for all instances are first min–max normalized across the dataset, and the selected CAM is displayed over time with a clean white-background design.

Parameters:
  • weights (ndarray of shape (n_instances, timesteps)) – The CAM weights computed for each instance.

  • instance_index (int) – Index of the instance whose CAM should be visualized.

Raises:
  • IndexError – If instance_index is out of range for weights.

  • ValueError – If weights is not a 2D array.

Note

The CAM values are normalized using MinMaxScaler prior to visualization to enable clearer comparison across instances.