model.interaction_features
Attributes
Classes
Implements a neural network model designed to explicitly model interactions between specific pairs of features |
Module Contents
- class model.interaction_features.InteractingFeaturesNN(n_features: int, weights: List[float | Tuple], interacting_features: List[Tuple[int, int]])
Bases:
torch.nn.SequentialImplements a neural network model designed to explicitly model interactions between specific pairs of features within the input data.
This model is capable of emphasizing or de-emphasizing the impact of these interactions on the model’s output through a specialized network architecture and custom weight assignments.
The network consists of linear layers combined with ReLU activation, structured to manipulate the input # features based on the predefined interactions. The interactions are modelled such that the influence of one feature on another can be either enhanced or canceled, according to the specified weights and the interaction mechanism implemented within the network.
- Inherits from:
torch.nn.Sequential: Parent class for implementing neural networks with modules defined in a sequential manner.
Initializes the InteractingFeaturesNN model with specified dimensions, weights, and interactions.
The architecture is designed to create a network that can process feature interactions by rearranging and weighting input features according to the specified interactions.
- Parameters:
n_features (int) – The total number of features in the input data. This includes both interacting and non-interacting features.
weights (list) – A list of floats or tuples specifying the weights to be applied to the features of the model. This list should have a len that matches the n_features, with each element corresponding to a feature in the input data.
interacting_features (list[tuple]) – A list where each tuple contains two integers representing the indices of the interacting features. The first element in the tuple is considered the impacting feature, and the second element is the feature being impacted.
- _validate_inputs(weights: List[float | Tuple], interacting_features: List[Tuple[int, int]]) None
Validates the inputs.
- Parameters:
weights (list) – A list of floats or tuples specifying the weights to be applied to the features of the model.
interacting_features (list[tuple]) – A list where each tuple contains two integers representing the indices of the interacting features.
- Raises:
AssertionError – If the inputs are not in the valid datatypes.
- _create_layer_weights(n_features: int, weights: List[float | Tuple], interacting_features: List[Tuple[int, int]]) Tuple
Creates the weights for the layers in a InteractingFeaturesNN model.
- Parameters:
n_features (int) – The total number of features in the input data.
weights (list) – A list of floats or tuples specifying the weights to be applied to the features of the model.
interacting_features (list[tuple]) – A list where each tuple contains two integers representing the indices of the interacting features.
- Returns:
Tuple containing the weights and activation functions for the neural network model.
- Return type:
tuple[list, NoneType, list]
- model.interaction_features.data