FeatureWhitelist

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 FeatureWhitelist(features: Sequence[str])[source]

Bases: object

Restrict the feature matrix to an explicit, externally derived list.

This is the bridge from a precision screen to habitat computation: the PreciseFeatureSet names the features that survived, and this method makes a habitat spec cluster exactly those – the workflow of Prior et al. (Radiol Artif Intell 2024;6(2):e230118), where only precise features may define habitats.

Unlike the data-driven filters, the column list is a CONSTRUCTOR argument: nothing is learned from the matrix, so the method is leakage-free by construction and fit simply echoes the list.

Parameters:
  • features – Feature names to keep, in output order. At least one is required, and every name must be present in the matrix – a

  • raises (missing feature breaks the "same features" contract and)

  • dropped. (rather than being silently)

__init__(features: Sequence[str]) → None[source]
property spec: Spec

Return the algorithm specification.

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

Echo the whitelist as the fitted state (nothing is learned).

Parameters:

block – Unit-by-feature matrix, checked against the whitelist.

Returns:

State naming the columns to keep.

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

Restrict the matrix to the whitelisted columns.

Parameters:
  • block – Matrix to transform.

  • state – State from fit() (the whitelist itself is used).

Returns:

The matrix with only the whitelisted columns.

Examples using habit.feature_preprocessing.FeatureWhitelist

Precise voxel features

Precise voxel features