pietro_molina
pietro_molina

Reputation: 127

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?

Upvotes: 0

Views: 94

Answers (1)

pietro_molina
pietro_molina

Reputation: 127

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)

Upvotes: 0

Related Questions