我正在努力完成一項相當簡單的任務。我有花車,而我想,以適應高斯混合模型有兩個高斯核的載體:如何在scikit-learn下繪製擬合高斯混合模型的概率密度函數?
from sklearn.mixture import GMM
gmm = GMM(n_components=2)
gmm.fit(values) # values is numpy vector of floats
我現在想爲陰謀我創建的混合模型的概率密度函數,但我似乎無法找到有關如何執行此操作的任何文檔。我應該如何最好地繼續?
編輯:
Here是我擬合數據的載體。以下是我如何做事更詳細的例子:
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')
擬合曲線看起來並不像我期望什麼東西。它看起來不像高斯,考慮到它是由高斯過程產生的,這有點奇怪。我瘋了嗎?
使用'積(X,np.exp(FIT),顏色= '紅色')'代替。因爲'gmm.score_samples'給出了'log'概率。 – emeth
@blz數據向量的鏈接已過期。 – shahensha