Combat wrapper
fyt.wrappers.combat_wrapper
¶
CombatWrapped
¶
Bases: BaseEstimator, TransformerMixin
A wrapper around pycombat.Combat to handle polars/pandas DataFrame input and output.
This wrapper extends pycombat.Combat to be compatible with scikit-learn pipelines. Accepts polars DataFrames as input, converts internally to pandas for pycombat, and returns polars DataFrames as output.
The wrapper extracts the batch column from the DataFrame during fit and transform,
and applies ComBat batch correction to the remaining numerical features. The
underlying Combat model always runs in parametric mode (mode="p").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_column
|
str
|
Name of the column containing batch identifiers. |
required |
feature_columns
|
list[str] | None
|
Optional list of feature column names to apply Combat to. If None, all numerical columns except batch_column are used. |
None
|
drop_batch_column
|
bool
|
If True, the batch column is dropped from the output DataFrame. If False (default), the batch column is kept. |
False
|
conv
|
float
|
Convergence criterion for EB optimization (default: 0.0001). |
0.0001
|
__getattr__(name)
¶
Delegate attribute access to the underlying Combat instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Attribute name. |
required |
Returns:
| Type | Description |
|---|---|
|
Attribute value from the underlying Combat instance. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the attribute is not found on the wrapper or the underlying Combat instance. |
fit(X, y=None)
¶
Fit the ComBat model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame | DataFrame | ndarray
|
polars or pandas DataFrame with features and batch column. |
required |
y
|
object
|
Ignored, present for sklearn compatibility. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
CombatWrapped
|
Fitted transformer. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the batch column is not found in the input DataFrame. |
get_feature_names_out(input_features=None)
¶
Return output feature names, honoring the dropped batch column.
transform returns the input columns in their original order with the
feature columns corrected, dropping the batch column when
drop_batch_column is set. The output feature names mirror that.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
Sequence[str] | ndarray | None
|
Names of the input columns. If None, the columns seen during fit are used. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray of output feature names. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the transformer is not fitted and no input_features were provided. |
set_output(*, transform=None)
¶
Set output configuration for compatibility with sklearn pipelines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transform
|
str | None
|
Output format for transform method. Not used in this wrapper. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
CombatWrapped |
CombatWrapped
|
The transformer itself. |
transform(X)
¶
Transform the data using fitted ComBat parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
DataFrame | DataFrame
|
polars or pandas DataFrame with features and batch column. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
X_out |
polars DataFrame with ComBat-corrected features. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the transformer has not been fitted yet. |
ValueError
|
If the batch column or a fitted feature column is not found in the input DataFrame. |