GaussianMixture initialization using component parameters - sklearn

前端 未结 3 1457
刺人心
刺人心 2021-02-10 01:16

I want to use sklearn.mixture.GaussianMixture to store a gaussian mixture model so that I can later use it to generate samples or a value at a sample point using score_sam

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-10 01:43

    It seems that it has a check that makes sure that the model has been trained. You could trick it by training the GMM on a very small data set before setting the parameters. Like this:

    gmix = mixture.GaussianMixture(n_components=2, covariance_type='full')
    gmix.fit(rand(10, 2))  # Now it thinks it is trained
    gmix.weights_ = weights   # mixture weights (n_components,) 
    gmix.means_ = mu          # mixture means (n_components, 2) 
    gmix.covariances_ = sigma  # mixture cov (n_components, 2, 2)
    x = gmix.sample(1000)  # Should work now
    

提交回复
热议问题