FeatureTable

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 FeatureTable(frame: DataFrame, id_columns: Tuple[str, ...], feature_columns: Tuple[str, ...], outcome: Outcome | None = None, provenance: Provenance | None = None)[source]

Bases: object

Feature table with explicit column semantics.

frame

The underlying table.

Type:

pandas.core.frame.DataFrame

id_columns

Columns identifying the unit of analysis, e.g. subject.

Type:

Tuple[str, …]

feature_columns

Columns usable as model inputs.

Type:

Tuple[str, …]

outcome

Declared study endpoint when present – a BinaryOutcome, MulticlassOutcome, ContinuousOutcome or SurvivalOutcome. An OBJECT rather than a column name because a survival endpoint occupies two columns, and because a name alone cannot tell a downstream metric whether the endpoint is a class or a quantity.

Type:

habit.contracts.outcome.Outcome | None

provenance

How this table was produced.

Type:

habit.contracts.provenance.Provenance | None

__post_init__() → None[source]

Validate that every declared column exists in the frame.

property outcome_column: str | None

Return the endpoint’s single column, for one-column endpoints only.

Convenience for the binary / multiclass / continuous cases, whose endpoint really is one column. It deliberately RAISES for survival rather than returning the time column: silently answering with half of a two-column endpoint would let a caller written for classification train on follow-up time as if it were a label.

Returns:

The endpoint column, or None when the table declares no endpoint.

Raises:

HABITAPIError – If the endpoint spans multiple columns.

feature_matrix() → DataFrame[source]

Return only the model-input columns, indexed by the id columns.

Named feature_matrix rather than features so it cannot be confused with running feature extraction, and because it returns a matrix-like frame rather than a list of features.

Returns:

A frame with the id columns as (possibly multi-) index and only the declared feature columns as data.

join(other: FeatureTable) → FeatureTable[source]

Join another table on the shared id columns.

Parameters:

other – Table to merge; must share id_columns.

Returns:

A new table whose provenance records both inputs.

Raises:

HABITAPIError – If the id columns do not match.

__init__(frame: DataFrame, id_columns: Tuple[str, ...], feature_columns: Tuple[str, ...], outcome: Outcome | None = None, provenance: Provenance | None = None) → None

Examples using habit.contracts.FeatureTable

Graph features

Graph features

Per-habitat radiomics

Per-habitat radiomics

Whole-habitat radiomics

Whole-habitat radiomics