2015-09-06 560 views
3

我已经用数据拟合GMM数据,我想计算模型的均方误差,我该怎么做?Python:如何计算分布的均方误差?

下面的代码生成数据

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观察,caluclate的kdensitity(x,y)-clf.score(x,y)。但我不确定这是否正确。

回答