【发布时间】:2015-09-06 08:59:18
【问题描述】:
我已经用 GMM 和数据拟合了数据,我想计算模型的均方误差,我该怎么做?
这是生成数据的代码
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from sklearn import mixture
import matplotlib as mpl
from matplotlib.patches import Ellipse
%matplotlib inline
n_samples = 300
# generate random sample, two components
np.random.seed(0)
shifted_gaussian = np.random.randn(n_samples, 2) + np.array([20, 5])
sample= shifted_gaussian
# fit a Gaussian Mixture Model with two components
clf = mixture.GMM(n_components=2, covariance_type='full')
clf.fit(sample)
# Then how can I calculate the Mean square error of the fitted model?
在我的想法中,我可以先生成kdensity 函数,然后对于sample 中的每个观察值,计算kdensitity(x,y)-clf.score(x,y)。但我不确定这是否是正确的方法。
【问题讨论】: