Interaction features capture the combined effect of two features that may not be visible when looking at each feature independently. For example, a model predicting house prices might benefit from a "rooms x area_per_room" interaction that neither feature alone conveys. Pairwise interactions are generated by multiplying each unique pair of features.
Given a feature matrix (samples x features), generate all pairwise interaction features by multiplying each unique pair of features, and append them to the original features.
For each sample with d features [x_1, x_2, ..., x_d], compute all unique pairwise products:
interactions=[xi⋅xj∣1≤i<j≤d]The output per sample is the original features followed by the interactions. The number of interactions is d(d-1)/2.
Return one expanded feature row for each input row.
Input: X = [[1, 2, 3]]
Output: [[1, 2, 3, 2, 3, 6]]
Explanation: Products for pairs (0, 1), (0, 2), and (1, 2) are appended after the original row.
Input: X = [[1, 2], [3, 4]]
Output: [[1, 2, 2], [3, 4, 12]]
Use a second feature index that always starts one position after the first.
Append pairwise products after a copy of the original row.
Sign in to take notes on this problem
Accepts: array
Interaction features capture the combined effect of two features that may not be visible when looking at each feature independently. For example, a model predicting house prices might benefit from a "rooms x area_per_room" interaction that neither feature alone conveys. Pairwise interactions are generated by multiplying each unique pair of features.
Given a feature matrix (samples x features), generate all pairwise interaction features by multiplying each unique pair of features, and append them to the original features.
For each sample with d features [x_1, x_2, ..., x_d], compute all unique pairwise products:
interactions=[xi⋅xj∣1≤i<j≤d]The output per sample is the original features followed by the interactions. The number of interactions is d(d-1)/2.
Return one expanded feature row for each input row.
Input: X = [[1, 2, 3]]
Output: [[1, 2, 3, 2, 3, 6]]
Explanation: Products for pairs (0, 1), (0, 2), and (1, 2) are appended after the original row.
Input: X = [[1, 2], [3, 4]]
Output: [[1, 2, 2], [3, 4, 12]]
Use a second feature index that always starts one position after the first.
Append pairwise products after a copy of the original row.
Sign in to take notes on this problem
Accepts: array