所以我使用了scikitlearn的Gaussian mixture models
(http://scikit-learn.org/stable/modules/mixture.html)来拟合我的数据,现在我想使用这个模型,我该怎么做呢?具体来说:
以下是您可能需要的代码:
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)
# plot sample scatter
plt.scatter(sample[:, 0], sample[:, 1])
# 1. Plot the probobility density distribution
# 2. Calculate the mean square error of the fitting model
更新: 我可以通过以下方式绘制分布图:
^{pr2}$
我认为这个结果是合理的,如果你稍微调整一下xlim和ylim:
相关问题 更多 >
编程相关推荐