cellmil.datamodels.transforms.base_transform

Base classes for feature transforms.

Classes

FittableTransform(name)

Base class for transforms that need to be fitted on training data.

Transform(name)

Base class for all feature transforms.

class cellmil.datamodels.transforms.base_transform.Transform(name: str)[source]

Bases: ABC

Base class for all feature transforms.

__init__(name: str)[source]

Initialize the transform.

Parameters:

name – Name of the transform for identification

abstract transform(features: Tensor) Tensor[source]

Apply the transform to features.

Parameters:

features – Input features tensor of shape (n_instances, n_features)

Returns:

Transformed features tensor

abstract get_config() Dict[str, Any][source]

Get the configuration dictionary for this transform.

Returns:

Dictionary containing transform configuration

abstract classmethod from_config(config: Dict[str, Any]) Transform[source]

Create transform instance from configuration dictionary.

Parameters:

config – Configuration dictionary

Returns:

Transform instance

save(path: Path) None[source]

Save the transform to disk.

Parameters:

path – Path to save the transform

classmethod load(path: Path) Transform[source]

Load transform from disk.

Parameters:

path – Path to load the transform from

Returns:

Transform instance

class cellmil.datamodels.transforms.base_transform.FittableTransform(name: str)[source]

Bases: Transform

Base class for transforms that need to be fitted on training data.

__init__(name: str)[source]

Initialize the fittable transform.

Parameters:

name – Name of the transform for identification

abstract fit(features: Tensor, feature_names: Optional[List[str]] = None) FittableTransform[source]

Fit the transform on training data.

Parameters:
  • features – Training features tensor of shape (n_instances, n_features)

  • feature_names – Optional list of feature names for logging

Returns:

Self for method chaining

fit_transform(features: Tensor, feature_names: Optional[List[str]] = None) Tensor[source]

Fit the transform and apply it to the features.

Parameters:
  • features – Features to fit and transform

  • feature_names – Optional list of feature names for logging

Returns:

Transformed features

transform(features: Tensor) Tensor[source]

Apply the transform to features.

Parameters:

features – Input features tensor

Returns:

Transformed features tensor

Raises:

RuntimeError – If transform hasn’t been fitted yet

abstract _transform_impl(features: Tensor) Tensor[source]

Implementation of the transform operation.

Parameters:

features – Input features tensor

Returns:

Transformed features tensor