![](/img/trans.png)
[英]python Fitting weighted data with Gaussian mixture model (GMM) with minimum on covariance
[英]Can I fix the mean of one component of a Gaussian Mixture Model in python before fitting?
我有興趣將 2 分量高斯混合 Model 擬合到下面顯示的數據。 但是,由於我在這里繪制的是歸一化為 0-1 之間的對數轉換計數,因此我的數據將采用的最大值為 0。當我嘗試使用 sklearn.mixture.GaussianMixture(下面的代碼)進行簡單擬合時,我得到合適的結果,這顯然不是我想要的。
from sklearn.mixture import GaussianMixture
import numpy as np
# start with some count data in (0,1]
logged_counts = np.log(counts)
model = GaussianMixture(2).fit(logged_counts.reshape(-1,1))
# plot resulting fit
x_range = np.linspace(np.min(logged_counts), 0, 1000)
pdf = np.exp(model.score_samples(x_range.reshape(-1, 1)))
responsibilities = model.predict_proba(x_range.reshape(-1, 1))
pdf_individual = responsibilities * pdf[:, np.newaxis]
plt.hist(logged_counts, bins='auto', density=True, histtype='stepfilled', alpha=0.5)
plt.plot(x_range, pdf, '-k', label='Mixture')
plt.plot(x_range, pdf_individual, '--k', label='Components')
plt.legend()
plt.show()
如果我可以將頂部分量的平均值固定為 0,並且只優化另一個平均值、兩個方差和混合分數,我會很高興。 (此外,我希望能夠為右側的組件使用半正常值。)有沒有一種簡單的方法可以使用 python/sklearn 中的內置函數來做到這一點,或者我是否必須自己構建 model 使用一些概率編程語言?
Afaik,你不能在 sklearn 中做你想做的事。
恕我直言,基本上有多種策略:(i)自己實現 GMM,(ii)切換到另一種語言/框架,(iii)適應 GMM 代碼,或(iv)適應。
(i) 除非您想自己學習,否則您可能不想這樣做。
(ii) 您可以使用stan並調整最后一段中的代碼以具有您選擇的固定組件(分布類型和參數)
(iii) 您可以做 (i) 但稍微修改sklearn 代碼或簡單地使用估計方法但您自己稍作修改。
(四)
.fit(data)
)。 然后從原始數據中減去結果參數(如選項 2)。 然后安裝一個 GMM。 找出下一個組件。希望這可以幫助:-)
Sklearn 提供了固定單個分布的平均值(也稱為“位置”)的可能性,如this other answer中所示。 這樣做的方法是向fit
方法提供floc
參數(代表“固定位置”)。
然而,正如 Drey 所提到的,這對於 GMM 是不可能的。 如果我們仔細查看代碼,我們可以看到GaussianMixture
擴展了 BaseMixture 。 當我們查看相應的fit
方法時,我們觀察到它執行了一個期望最大化算法,並且它不承認任何來自固定結果之類的東西。
將此功能添加到現有代碼中可能會涉及與 EM 實現的激烈爭論,而且它可能會導致比其他任何事情更多的問題。
這就是說,對於這種分布,GMM 似乎確實不是最好的 model。 目不轉睛地看,似乎混合了 beta 發行版可能會奏效。
令人驚嘆的 Python 庫pomegranate它非常易於使用,並允許您擬合任意分布的混合物。 在這里您可以看到支持的發行版的代碼,似乎存在 beta:
https://pomegranate.readthedocs.io/en/latest/
干杯!
安德烈斯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.