Impute

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class Impute(strategy: str = 'mean')[source]

Bases: object

Replace non-finite feature values with a learned per-column statistic.

Every other method assumes finite input: a quantile computed over a column containing infinity is meaningless, and scikit-learn refuses NaN outright. So this belongs FIRST in a chain, and both chains insert it automatically when a configuration does not name it – recording it in their spec, so the step is never applied invisibly.

v0.1 ran this logic as a hard-coded prologue rather than a configurable step, which left the strategy unreachable from a study’s configuration even though the underlying helper already supported alternatives.

Parameters:

strategy – mean or median of each column’s finite values, or zero. Columns with no finite value at all impute to 0.0 regardless, so one unusable modality cannot invalidate a subject.

__init__(strategy: str = 'mean') → None[source]
property spec: Spec

Return the algorithm specification.

fit(block: DataFrame) → Dict[str, Any][source]

Learn the per-column replacement values.

Parameters:

block – Unit-by-feature matrix to learn from.

Returns:

State to pass to transform().

transform(block: DataFrame, state: Mapping[str, Any]) → DataFrame[source]

Replace non-finite values with the learned statistics.

Parameters:
  • block – Matrix to repair.

  • state – State from fit().

Returns:

A finite matrix.