KMeansHabitatModelFitter

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 KMeansHabitatModelFitter(n_habitats: int | None = None, min_habitats: int = 2, max_habitats: int = 10, validation: str | Sequence[str] = 'elbow', n_init: int = 50, max_iter: int = 300)[source]

Bases: object

Learn population habitats by k-means over pooled supervoxel features.

This is the cohort-level step: the ONLY place where information crosses subject boundaries. When n_habitats is omitted, the habitat count is selected by a validation score over min_habitats..max_habitats – the same model-selection behaviour the v0.1 clustering classes exposed through the configuration schema, here expressed as constructor params.

The fitter is Seedable; the seed is applied to k-means initialisation at fit time.

Parameters:
  • n_habitats – Fixed habitat count, or None to select it by validation.

  • min_habitats – Smallest candidate count during selection.

  • max_habitats – Largest candidate count during selection.

  • validation – Selection criterion, or a list of criteria that each cast one vote: "elbow" / "kneedle" / "inertia" (Kneedle knee of the inertia curve; default "elbow"), "silhouette" / "calinski_harabasz" / "gap" (maximise), or "davies_bouldin" (minimise). Since v1.0 elbow is an alias of kneedle; see habit.kernels.cluster_selection. The default is the community-used inertia elbow over min_habitats=2 .. max_habitats=10.

  • n_init – k-means restarts per candidate count.

  • max_iter – Maximum k-means iterations per fit. Defaults to the scikit-learn default (300), which is also the value the v0.1 configuration schema recorded.

__init__(n_habitats: int | None = None, min_habitats: int = 2, max_habitats: int = 10, validation: str | Sequence[str] = 'elbow', n_init: int = 50, max_iter: int = 300) → None[source]
property spec: Spec

Return the algorithm specification.

set_random_state(seed: int) → None[source]

Set the seed applied to k-means initialisation at fit time.

fit(units: Sequence[Supervoxelization], *, cohort: Cohort | None = None) → HabitatModel[source]

Learn the shared habitat definition from all subjects.

Parameters:
  • units – Supervoxelizations in a defined, reproducible order.

  • cohort – Cohort the units came from, fingerprinted into the model.

Returns:

A self-contained habitat model applicable to unseen subjects.

Examples using habit.habitat_model.KMeansHabitatModelFitter

Preprocessing voxel texture before clustering

Preprocessing voxel texture before clustering

Clustering habitats from a derived map

Clustering habitats from a derived map

Clustering habitats from a texture field

Clustering habitats from a texture field

Preprocessing features before clustering

Preprocessing features before clustering

Fitting a cohort habitat model

Fitting a cohort habitat model

Assigning habitat labels

Assigning habitat labels

Why habitat ids must be matched

Why habitat ids must be matched

Matching maps of the same voxels by overlap

Matching maps of the same voxels by overlap

Prototype matching step by step

Prototype matching step by step

Naming a new cohort with frozen prototypes

Naming a new cohort with frozen prototypes

What matching changes in a cohort feature table

What matching changes in a cohort feature table

Matching habitat labels across subjects

Matching habitat labels across subjects