Model Selection API¶
select_model fits a grid of (n_components, covariance_type) combinations
and compares them by BIC, AIC, or ICL; ModelSelectionResult is what it
returns. See the Clustering Metrics user guide
for a worked example.
select_model(X, n_components=range(1, 11), covariance_types=GPCM_CODES, criterion='bic', n_init=1, random_state=None, **gmm_kwargs)
¶
Fit GaussianMixture(n_components=K, covariance_type=type, ...) for
every (K, type) pair in the Cartesian product of n_components and
covariance_types, and return the comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
Tensor
|
Data to fit, shape (n_samples, n_features). |
required |
n_components
|
iterable of int
|
Component counts to try. (default: |
range(1, 11)
|
covariance_types
|
iterable of str
|
Covariance types to try, as tgmm names or mclust GPCM codes
(case-insensitive) -- see |
GPCM_CODES
|
criterion
|
str
|
Which score to minimise when choosing |
'bic'
|
n_init
|
int
|
Forwarded to every |
1
|
random_state
|
int
|
Forwarded to every |
None
|
**gmm_kwargs
|
Any other |
{}
|
Returns:
| Type | Description |
|---|---|
ModelSelectionResult
|
|
Notes
A combination whose fit raises (e.g. a singular covariance at a large
K) is recorded in .table with every score None and is excluded
from the criterion-minimising search -- the sweep as a whole does not
fail because one combination did.
Source code in tgmm/model_selection.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
ModelSelectionResult
dataclass
¶
The result of a :func:select_model sweep.
Attributes:
| Name | Type | Description |
|---|---|---|
table |
list of dict
|
One row per |
best_ |
GaussianMixture or None
|
The fitted model minimising the sweep's |
models_ |
dict
|
Maps |