Python: 如何计算分布的均方误差?

4

我已经用数据拟合了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)。但我不确定这是否是正确的方法。

1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接