如何从 python 中的高斯混合创建随机变量(样本)
How can I create a random variables (samples) from Gaussian mixture in python
我正在尝试将高斯混合拟合到 3 个变量数据集。我已经使用 3 个高斯模型在 python 中获得了一个 GMM 模型。
我的问题是:
- 如何从 GMM 创建 PDF,就像 matlab 中的函数一样?
- 如何创建随机变量 (3d) 或从 GMM 中抽样?
很多人都上传了类似的问题,但我一直没有得到直接的答案。请提供有关如何从 GMM 中采样的代码示例。
首先您需要知道创建 GMM 模型需要 3 个参数:
- 数据点
- 集群的平均值
- 协方差矩阵
let for each data point i and for each cluster in you case k = 3 i am
already assuming you have mean of each cluster as an list i.e means
and Covariance matrix for each cluster in covariances i.e list of
covariance for each cluster.then the code will look like this which
give you the value of multivariate normal function for each data point
i and for each cluster k is :
import numpy as np
from scipy.stats import multivariate_normal
mnf= np.zeros((n_data, n_clusters))
for i in range(n_data):
for k in range(n_clusters):
mnf[i, k] = multivariate_normal.pdf(data[i],means[k],covariances[k])
我正在尝试将高斯混合拟合到 3 个变量数据集。我已经使用 3 个高斯模型在 python 中获得了一个 GMM 模型。
我的问题是:
- 如何从 GMM 创建 PDF,就像 matlab 中的函数一样?
- 如何创建随机变量 (3d) 或从 GMM 中抽样?
很多人都上传了类似的问题,但我一直没有得到直接的答案。请提供有关如何从 GMM 中采样的代码示例。
首先您需要知道创建 GMM 模型需要 3 个参数:
- 数据点
- 集群的平均值
- 协方差矩阵
let for each data point i and for each cluster in you case k = 3 i am already assuming you have mean of each cluster as an list i.e means and Covariance matrix for each cluster in covariances i.e list of covariance for each cluster.then the code will look like this which give you the value of multivariate normal function for each data point i and for each cluster k is :
import numpy as np
from scipy.stats import multivariate_normal
mnf= np.zeros((n_data, n_clusters))
for i in range(n_data):
for k in range(n_clusters):
mnf[i, k] = multivariate_normal.pdf(data[i],means[k],covariances[k])