【问题标题】:Python: How to calculate the mean square error of a distribution?Python:如何计算分布的均方误差?
【发布时间】: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)。但我不确定这是否是正确的方法。

【问题讨论】:

    标签: python scipy


    【解决方案1】:

    在此处查看文档:

    http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html

    我觉得你可以试试:

    covariances = clf.fit(sample).covariances_ MSE = np.diag(covariances)

    这将为您提供拟合参数的协方差矩阵。然后矩阵的对角线值将为您提供拟合模型参数的均方误差。

    或者它可能是工作:

    clf.fit(sample).get_params(deep=True)
    

    【讨论】:

      猜你喜欢
      • 2015-05-17
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2020-05-13
      • 1970-01-01
      • 2018-12-27
      • 2021-08-21
      相关资源
      最近更新 更多