The sklearn.mixture object GaussianMixture provides the framework to fit a GMM to provided data, but how can one add/remove components from a sklearn gmm object for further warm start?
The sklearn.mixture object GaussianMixture provides the framework to fit a GMM to provided data, but how can one add/remove components from a sklearn gmm object for further warm start?
Given an np.array X:
X = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
One can easily fit a GMM to the data with the .fit() method:
gm = GaussianMixture(n_components=2, random_state=1).fit(X)
To change a parameter (e.g. number of components), invoke the .set_param() method, set the warm_start value to True, and change the desired parameter. One can then fit the gmm to the data again, but using the previous fitting as initialization:
gm.set_params(warm_start=True, n_components=3)