Data Science Pilot Action Set
The detectInteractions Action
- What Types of Interactions Are Detected by This Action?
- Missing Values and Improper Binary Format
- Output of Interaction Detection Analysis
- Seed
- Target
- Event
- Inputs
- Sparse Inputs and Input levels
- Number of Background Pairs
- Number of Projections
- Maximum Number of Interactions
- Maximum Distance
- Minimum Interaction Probability
- Output Tables
The detectInteractions action implements a customized version of the XYZ algorithm for interaction searches in high-dimensional spaces (Thanei, Meinshausen, and Shah 2018). For a data table that contains a response variable and a set of predictor variables, this action assesses the interaction between pairs of predictor variables on the one hand, and assesses the correlation of this interaction with the response variable on the other hand. Formally, for a prediction problem in which there are n observations, a response vector , and an associated matrix of predictors
, the XYZ algorithm is designed to search for and detect interactions in the setting where the number of variables p is very large.
The run-time complexity of finding such interactions by using a naive and brute-force approach is , which is computationally prohibitive even for moderate n and p. The XYZ algorithm reduces this complexity by means of two techniques: random projection and sorting. Random projection breaks the dependency on n and decreases the complexity to
, whereas sorting breaks the dependency on
and decreases the complexity to
in the worst case. Both techniques render the search for interacting variables into an efficient and scalable algorithm for both scenarios, large n and large p.
The XYZ algorithm operates only on binary predictor variables that are represented as numeric (interval) variables. The detectInteractions action performs data preprocessing to transform the interval and nominal variables in the input data set into binary variables. The interval variables are discretized using quantile discretization. Nominal variables are grouped into low-cardinality and high-cardinality nominal variables by using an internally set cardinality threshold, which is currently set to 256. The low-cardinality nominal variables are grouped using tree-based techniques, and the high-cardinality nominal variables are grouped using target encoding, followed by quantile discretization. These data preprocessing steps result in sparse-coded variables that are then converted to a dense binary representation by using one-hot encoding.
In some cases, you might have a binary data set. In such cases, the data preprocessing step is not needed. You can request that the detectInteractions action skip the data preprocessing step by specifying the sparse parameter. Your binary data must be in one of three formats: ,
, or
. Note that all internal calculations are based on the
representation. If the data are represented using the
format, they are converted on the fly to
during the calculations. Similarly, if the data are represented using the
format, they are converted on the fly to
during the calculations. The sparse format representation is discussed further in the following sections, which introduce the
sparseInputs and inputLevels parameters.
The response variable for the detectInteractions action is flexible in order to accommodate different types of prediction problems. For regression problems, the response variable has to be of numeric (interval) type; that is, . For classification problems, either binary or multiclass, the response variable can be of numeric (interval) type or character (or string) type. This is discussed further in the following sections, where the
event parameter is introduced.
What Types of Interactions Are Detected by This Action?
The types of interactions that the detectInteractions action detects are ,
, and
. For binary data, this is the frequency at which the product of the predictor variables,
, is equal to (or correlates with) the response Y. In this context, this is the frequency at which the sign of the product of two binary predictors agrees with the sign of the response variable. Note that the relationship between the inner product and the response variable is linear, and therefore you can expect that high-frequency interacting variables that are detected under the notion of interactions defined earlier can improve the prediction capability of linear prediction models when such interacting variables are included in the model.
Missing Values and Improper Binary Format
All observations that have missing values or observations that have an improper binary format (as indicated earlier) are ignored and not considered for calculations and estimation steps. The "AnalysisInfo" table described in the next section indicates the actual number of observations that the detectInteractions action uses.
Output of Interaction Detection Analysis
The detectInteractions action generates two tables as output. The first output table is the "Interacting Variables" table, which lists the pairs of interacting variables, sorted in descending order of interaction strength. For classification problems, the interaction strength is the probability that both variables would interact in the current data table; the interaction strength value is between 0 and 1. For regression problems, the interaction strength is a nonnegative number that can be greater than 1. Each entry in the table describes one pair of interacting variables, ,
, and
. The table has five columns. The first and second columns indicate the variable name and ID of variable
, and the third and fourth columns indicate the variable name and ID of variable
. Column five indicates the interaction strength of the pair
.
The second output table is the "AnalysisInfo" table, which displays the number of observations that are read from the input data table and the number of observations that are actually used by the detectInteractions action for estimating the interactions between variables. The latter is the number of observations without any missing values or improper binary format values.
Seed
The seed parameter initializes the internal pseudorandom number generator (used by the action) to a specific initial value. This is essential for reproducing results and validating calculations. When the seed parameter is omitted, the seed is generated by reading the time of day from the computer’s clock.
Target
The target parameter specifies the variable name (as a string) in the input data table that should be treated as the response variable for the detectInteractions action. For regression problems, the target variable must be of numeric (interval) type, whereas for classification problems, either binary or multiclass, the target variable can be numeric (interval) or character (string). The event parameter, which is described in the next section, is synchronized with the target parameter so that the action can achieve the desired functionality.
Event
The event parameter, which is specified as a string, sets the desired type of prediction problem. If this parameter is not specified, then the action is in regression mode, and the specified target parameter is expected to be of numeric (interval) type; otherwise, the action exits and issues an appropriate error message.
For classification problems (binary or multiclass), the event parameter needs to be set in order to indicate the label of the class (or category) that the action is to treat as the positive label (). All other classes or categories are treated as the negative label (
). Note that the
event parameter accepts only one string as the label for the positive class or category. If the specified label is not found in the table column that is specified by the target parameter, the action exits and issues an appropriate error message.
Examples
For classification problems, the response variable can be of numeric (interval) or character (or string) type. For example, if the response variable or
, then the
event parameter can be specified using the following values: 'yes' for the first case and 'medium' for the second case.
The detectInteractions action internally assigns the positive and negative response values as follows. For the first case, observations that are labeled with the string 'yes' are assigned a positive response, , and observations that are labeled with the string 'no' are assigned the negative response,
. For the second case, observations that are labeled with the string 'medium' are assigned the positive response
, and observations that are labeled with the string 'small' or 'large' are assigned the negative response
.
As another example of classification problems in which you have an integer target (or response) variable, suppose that the response variable and you want to treat class 5 as the category with the positive label (
). Then, the
event parameter needs to be set to the string '5'. All observations that have labels are assigned the negative response,
.
For the last example, let . In this case, setting the
event parameter to "–1" assigns the positive label () to all observations from class
and assigns the negative label (
) to all observations from classes
.
Inputs
The detectInteractions action can take as input a list that is a subset of variables from the main variables in the specified input CAS table. Note that the subset needs to be from the numeric variables in the input CAS table. If the inputs parameter is not specified, then the default is to consider all numeric (interval) variables in the input CAS table, except for the variable specified by the target parameter. However, if the inputs parameter is specified, the interaction is run only on those variables in the inputs parameter list. This list should not contain duplicate variable names or the variable name specified in the target parameter. The action uses the order of the variable names that are specified in the inputs parameter list.
Sparse Inputs and Input levels
The sparseInputs and inputLevels parameters enable the detectInteractions action to handle and operate on data in sparse format. Sparse format is intended to be a compact representation of data that contain only nominal variables and are encoded using the sparse one-hot-encoding scheme.
As an example, consider a data table that contains three nominal variables, ,
, and
, where
has two levels,
has three levels, and
has five levels. Suppose that observation i has the following values for the three nominal variables: level 1 for
, level 2 for
, and level 4 for
. Using standard one-hot-encoding, observation i can be represented as follows:
. However, sparse format has a more compact representation than the explicit one-hot-encoding format; in particular,
. That is, each entry in sparse format indicates which level is "on" (or selected) for each nominal variable.
To enable the detectInteractions action to analyze data in sparse format, the sparseInputs parameter, which is specified as a Boolean variable, must be set to True. The default value for this parameter is False. If the value is True, then two other parameters must be specified: the inputs and inputLevels parameters. The inputs parameter is needed to specify the nominal variables from the specified input CAS table, as well as their order. The inputLevels parameter. which is specified as a list of integers, must be provided in order to specify the number of nominal variables and the number of levels for each nominal variable. For the example given earlier, the inputs and inputLevels parameters must be specified using the values and
, respectively.
If all the p nominal variables in a data table have the same number of levels—say, m—it is sufficient to set the value of the inputLevels parameter to . Also, if there are
nominal variables in a data table, and the last k variables have the same number of levels, it is sufficient to indicate the level for the last k variables only once. As an illustration, consider the earlier example and suppose that there are five (5) new nominal variables in addition to
,
, and
, where each new nominal variable has 10 levels. Then, the value of the
inputLevels parameter can be set to , without repeating the last entry five times.
Number of Background Pairs
The XYZ algorithm needs an estimate for the average interaction strength between predictor variables in the data under consideration for interaction analysis. On the basis of this estimate, the algorithm sets some internal parameters that are related to the random projection step. To compute this estimate, the algorithm needs a random sample from the pairs of variables in the data. The numPairs parameter is used to set the size of this random sample. You can either specify the size of this random sample or use the default value (zero) for this parameter to let the algorithm determine the size of the sample. For p variables, this value is determined according to the following rule:
Number of Projections
The XYZ algorithm achieves its efficiency for large numbers of observations n by using random projections. For each random projection, the algorithm selects a set of promising (or potential) interacting pairs of variables from a special list. Such promising interacting variables are defined here as candidates, or promising candidates. For repeated random projections, promising candidates occur more than once in the list of candidates. Other interacting pairs of variables might not occur frequently in this list.
The numProjections parameter is used to set the number of random projections that the algorithm has to perform. The larger the number of random projections, the longer the list of candidates, because a longer list offers a better opportunity for weakly interacting variables to occur more than once. On the other hand, a small number of random projections can capture strong interacting variable pairs only if such a strong interaction exists in the data.
Note that you can also control the size of the list of candidates by using the maxNumInteractions parameter, which is described in the next section. The minimum value of the numProjections parameter is 1, the maximum value is 100,000, and the default value is 10. For large p, it is recommended that you increase the value of the numProjections parameter gradually and compare the final lists of interacting variables.
Maximum Number of Interactions
The maxNumInteractions parameter controls the size of the list of promising candidates per random projection. The minimum size of this list is 10, the maximum is 10,000, and the default is 100. To get an idea of how this parameter works with the numProjections parameter, consider the following example. If the value of the maxNumProjections parameter is 10, and the value of the maxNumInteractions parameter is 1,000, then the final number of potential candidates after 10 random projections is , assuming that each potential interacting pair of variables appears exactly once in all 10 projections. Note that the actual number of promising candidates in this list is determined by the
maxDistance parameter, which is described in the next section.
Maximum Distance
The maxDistance parameter, or , specifies the maximum threshold of the distance between any two variables
and
,
, in order to assess whether they are a potential candidate pair. The distance that is considered in this setting is the
distance, or
. According to the analysis of the XYZ algorithm, in the ideal setting where two variables strongly interact together, the distance between them should be zero or close to zero. However, because this might not be feasible in practical settings,
is allowed to be strictly greater than zero, and hence the pair
is added to the list of potential candidates if
. The default value of
or the
maxDistance parameter is 1E–08.
Note that a smaller value of implies searching only for strong interacting pairs of variables and will slowly fill the list of potential candidates discussed earlier. On the other hand, a larger value of
implies searching for strong and weak interacting variables and will quickly fill the list of interacting candidates. In this case, if the list is not large enough, the algorithm can easily miss strong potential candidates.
Minimum Interaction Probability
After obtaining the final candidate lists from all random projections, the XYZ algorithm computes the actual interaction strength of all candidate pairs and then sorts all pairs in decreasing order of interaction strength. For ,
, if this is a classification problem, the interaction strength is defined as the probability that the two variables
and
interact in this data table. The
minInteractionProbability parameter, or , is a threshold of the smallest interaction probability (or strength) for the final output list of interacting variables. That is, any candidate pair whose interaction strength is smaller than
is discarded from the final output of the
detectInteractions action. The minimum value of is 0, the maximum value is 1, and the default value is 0.01. For regression problems, the interaction strength values are also listed in descending order, and the cutoff value is 0.01 as well.
Output Tables
The results that the detectInteractions action produces are stored in tables. You can access these tables by their names, which are shown in Table 1. For more information about the contents of these tables, see the section Output of Interaction Detection Analysis.
Table 1: ODS Tables Produced by the detectInteractions Action
| Table Name | Description | Parameter |
|---|---|---|
| AnalysisInfo | Information about run-time parameters | Default |
| InteractingVariables | Information about interacting variables | Default |