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:
objectLearn 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_habitatsis omitted, the habitat count is selected by a validation score overmin_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
Noneto select it byvalidation.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.0elbowis an alias ofkneedle; seehabit.kernels.cluster_selection. The default is the community-used inertia elbow overmin_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]
- 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.