torch_openreml.utils.interaction¶
- torch_openreml.utils.interaction(*args, sep='⋈')[source]¶
Construct an interaction term from two or more categorical vectors.
Joins the corresponding elements of each input vector into a single string separated by
sep, producing a new categorical vector whose levels represent combined factor combinations.- Parameters:
*args (list or tuple of str) – Two or more categorical vectors of equal length.
sep (str, optional) – Separator inserted between joined levels. Defaults to
"⋈"(U+22C8, the bowtie symbol).
- Returns:
Interaction vector of the same length as the inputs.
- Return type:
list of str
- Raises:
ValueError – If no inputs are provided.
TypeError – If any input is not a list or tuple of strings.
Example:
from torch_openreml.utils import interaction a = ["control", "control", "treatment"] b = ["male", "female", "male"] interaction(a, b)
['control⋈male', 'control⋈female', 'treatment⋈male']