我正在努力完成一项相当简单的任务。我有一个浮点向量,我想将其拟合为具有两个高斯核的高斯混合模型:
from sklearn.mixture import GMM
gmm = GMM(n_components=2)
gmm.fit(values) # values is numpy vector of floats
我现在想绘制我创建的混合模型的概率密度函数,但我似乎找不到任何有关如何执行此操作的文档。我应该如何最好地进行?
Edit:
Here https://dl.dropboxusercontent.com/u/6160029/kde.pickle是我正在拟合的数据向量。下面是我如何做事情的更详细的示例:
from sklearn.mixture import GMM
from matplotlib.pyplot import *
import numpy as np
try:
import cPickle as pickle
except:
import pickle
with open('/path/to/kde.pickle') as f: # open the data file provided above
kde = pickle.load(f)
gmm = GMM(n_components=2)
gmm.fit(kde)
x = np.linspace(np.min(kde), np.max(kde), len(kde))
# Plot the data to which the GMM is being fitted
figure()
plot(x, kde, color='blue')
# My half-baked attempt at replicating the scipy example
fit = gmm.score_samples(x)[0]
plot(x, fit, color='red')
拟合的曲线看起来与我预期的完全不一样。它甚至看起来都不是高斯分布的,这有点奇怪,因为它是由高斯过程产生的。我疯了吗?