ColumnTransformer
Module: strata.compose • Kind: struct • Traits: Copyable, Movable, Transformer
Source: strata/compose/column_transformer.mojo
struct ColumnTransformer[*Transformers: Transformer](Copyable, Movable, Transformer)from strata.compose import ColumnTransformerApplies a heterogeneous variadic sequence of transformers to column subsets of a feature matrix.
Transforms designated column subsets independently using compile-time unrolled variadic tuples and horizontally stacks the output representations with configurable remainder handling.
Parameters (Compile-Time)
Section titled “Parameters (Compile-Time)”| Parameter | Description |
|---|---|
Transformers |
Variadic pack of Transformer types. |
Constructors
Section titled “Constructors”def __init__( out self, transformers: Tuple[*Self.Transformers], column_specs: List[List[Int]], remainder: String = "drop",)Initializes a ColumnTransformer with variadic transformers and column specs.
| Argument | Type | Description |
|---|---|---|
transformers |
Tuple[*Self.Transformers] |
Tuple of transformer instances satisfying the Transformer trait. |
column_specs |
List[List[Int]] |
List of column index lists matching the count of transformers. |
remainder |
String |
Strategy for unselected columns (‘drop’ or ‘passthrough’). Default ‘drop’. |
Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
transformers |
Variadic tuple of transformer instances. |
column_specs |
List of column index lists corresponding to each transformer step. |
remainder |
Strategy for unselected columns (‘drop’ or ‘passthrough’). Default ‘drop’. Fitted Attributes: |
remainder_cols_ |
Discovered unselected column indices when remainder=‘passthrough’. |
n_features_in_ |
Total number of feature columns seen during fit. |
is_fitted |
Boolean flag indicating if transformer has been fitted. |
Methods Overview
Section titled “Methods Overview”| Method | Description |
|---|---|
ColumnTransformer.fit() |
Fits all transformers on their respective designated column subsets. |
ColumnTransformer.transform() |
Transforms column subsets and horizontally stacks output representations. |
ColumnTransformer.fit_transform() |
Fits all transformers and returns concatenated transformed output. |
Method Details
Section titled “Method Details”ColumnTransformer.fit()
Section titled “ColumnTransformer.fit()”def fit[in_dtype: DType](mut self, X: Matrix[in_dtype])
def fit[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],)Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Fits all transformers on their respective designated column subsets.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Input feature matrix of shape . |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
ColumnTransformer.transform()
Section titled “ColumnTransformer.transform()”def transform[in_dtype: DType]( self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def transform[feat_dtype: DType, target_dtype: DType]( self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[feat_dtype, target_dtype]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Transforms column subsets and horizontally stacks output representations.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Input feature matrix of shape . |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype] — Matrix[in_dtype]: Concatenated transformed feature matrix.
ColumnTransformer.fit_transform()
Section titled “ColumnTransformer.fit_transform()”def fit_transform[in_dtype: DType]( mut self, X: Matrix[in_dtype],) -> Matrix[in_dtype]
def fit_transform[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],) -> Dataset[feat_dtype, target_dtype]Overload Note: This method accepts either a standard
X: Matrixor a unifieddataset: Datasetcontainer.
Fits all transformers and returns concatenated transformed output.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[in_dtype] |
Input feature matrix of shape . |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix. (Can be provided alternatively in place of X) |
Returns: Matrix[in_dtype] — Matrix[in_dtype]: Concatenated transformed feature matrix.
Section titled “Returns: Matrix[in_dtype] — Matrix[in_dtype]: Concatenated transformed feature matrix.”Example
Section titled “Example”from strata import Matrix, StandardScaler, OneHotEncoder, ColumnTransformer
var ct = ColumnTransformer( (StandardScaler(), OneHotEncoder()), List[List[Int]]([0, 1], [2]), remainder="passthrough",)