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)
。但我不確定這是否正確。