sklearn.mixture.BayesianGaussianMixture?

class sklearn.mixture.BayesianGaussianMixture(*, n_components=1, covariance_type='full', tol=0.001, reg_covar=1e-06, max_iter=100, n_init=1, init_params='kmeans', weight_concentration_prior_type='dirichlet_process', weight_concentration_prior=None, mean_precision_prior=None, mean_prior=None, degrees_of_freedom_prior=None, covariance_prior=None, random_state=None, warm_start=False, verbose=0, verbose_interval=10)

[源碼]

高斯混合的變分貝葉斯估計。

此類允許推斷高斯混合分布參數的近似后驗分布。組件的有效數量可以從數據中推斷出來。

此類實現了兩種類型的權重分布先驗:一種是具有Dirichlet分布的有限混合模型,另一種是具有Dirichlet過程的無限混合模型。在實際應用中,Dirichlet過程推理算法是近似的,并使用具有固定最大組件數的截斷分布(稱為Stick-breaking representation)。實際使用的組件數量絕大多數取決于數據。

版本0.18中的新功能。

用戶指南中閱讀更多內容。

參數 說明
n_components int, defaults to 1.
混合高斯模型的個數,默認為1。根據數據和weight_concentration_prior模型的值,模型可以通過將某些組件設置weights_為非常接近零的值來決定不使用所有組件。因此,有效分量的數量小于n_components。
covariance_type {‘full’, ‘tied’, ‘diag’, ‘spherical’}, defaults to ‘full’
描述要使用的協方差參數類型的字符串。必須是以下之一:
'full' (each component has its own general covariance matrix),
'tied' (all components share the same general covariance matrix),
'diag' (each component has its own diagonal covariance matrix),
'spherical' (each component has its own single variance).
tol float, defaults to 1e-3.
EM 迭代停止閾值,默認為 1e-3 即 0.001。當(關于模型的訓練數據)可能性的下限平均增益低于此閾值時,EM迭代將停止。
reg_covar float, defaults to 1e-6.
協方差對角非負正則化,保證協方差矩陣均為正
max_iter int, defaults to 100.
要執行的EM迭代次數。
n_init int, defaults to 1.
初始化次數,用于產生最佳初始參數,默認為 1
init_params {‘kmeans’, ‘random’}, defaults to ‘kmeans’.
用于初始化權重,均值和協方差的方法。必須是以下之一:
'kmeans' : responsibilities are initialized using kmeans.
'random' : responsibilities are initialized randomly.
weight_concentration_prior_type str, defaults to ‘dirichlet_process’.
描述先前權重濃度類型的字符串。必須是以下之一:
'dirichlet_process' (using the Stick-breaking representation),
'dirichlet_distribution' (can favor more uniform weights).
weight_concentration_prior float,None, optional.
每個組分在權重分布上的dirichlet濃度(dirichlet)。這在文獻中通常稱為伽瑪。濃度越高,中心的質量越大,活性組分越多。參數的值必須大于0。如果為None,則將其設置為:1. / n_components.
mean_precision_prior float,None, optional.
平均分布(高斯分布)的精度先驗。控制可以放置方法的范圍。值越大,聚類平均值就越集中。參數的值必須大于0。如果為“無”,則設置為1。
mean_prior array-like, shape (n_features,), optional
均值上的先驗分布(高斯)。如果為None,則將其設置為X的平均值。
degrees_of_freedom_prior float,None, optional.
協方差分布上的自由度數的先驗(Wishart)。如果為None,則將其設置為n_features
covariance_prior float or array-like, optional
協方差分布的先驗(Wishart)。如果為None,則使用X的協方差初始化半協方差先驗。形狀取決于covariance_type
(n_features, n_features) if 'full',
(n_features, n_features) if 'tied',
(n_features) if 'diag',
float if 'spherical'
random_state int, RandomState instance or None, optional (default=None)
控制分配給用于初始化參數的方法的隨機種子(請參閱參考資料init_params)。另外,它控制擬合分布中隨機樣本的生成(請參見方法sample)。為多個函數調用傳遞可重復輸出的int值。請參閱詞匯表
warm_start bool, default to False.
如果'warm_start'為True,則最后一次擬合的解決方案將用作下一次fit()的初始化。在類似問題上多次調用fit時,這可以加快收斂速度。請參閱詞匯表
verbose int, default to 0.
啟用詳細輸出。如果為1,則打印當前的初始化和每個迭代步驟。如果大于1,則還將打印對數概率和每個步驟所需的時間。
verbose_interval int, default to 10.
下一次打印之前完成的迭代次數。
屬性 說明
weights_ array-like, shape (n_components,)
每個混合元素權重
means_ array-like, shape (n_components, n_features)
每個混合元素的平均值。
covariances_ array-like
每個混合元素的協方差。形狀取決于covariance_type
(n_components,) if 'spherical',
(n_features, n_features) if 'tied',
(n_components, n_features) if 'diag',
(n_components, n_features, n_features) if 'full'
precisions_ array-like
每個混合元素精度矩陣,精度矩陣是協方差矩陣的逆。協方差矩陣是對稱正定的,因此高斯混合可以用精度矩陣等價地參數化。存儲精度矩陣而不是協方差矩陣使得在測試時間計算新樣本的對數似然更有效。它的依靠協方差類型covariance_type
(n_components,) if 'spherical',
(n_features, n_features) if 'tied',
(n_components, n_features) if 'diag',
(n_components, n_features, n_features) if 'full'
precisions_cholesky_ array-like
每個混合元素的精確矩陣的cholesky分解。精度矩陣是協方差矩陣的逆。協方差矩陣是對稱正定的,因此高斯混合可以用精度矩陣等價地參數化。存儲精度矩陣而不是協方差矩陣使得在測試時間計算新樣本的對數似然更有效。它的依靠協方差類型covariance_type
(n_components,) if 'spherical',
(n_features, n_features) if 'tied',
(n_components, n_features) if 'diag',
(n_components, n_features, n_features) if 'full'
converged_ bool
bool類型,在fit()中達到收斂時為true,否則為false。
n_iter_ int
最佳擬合達到收斂所使用的步數。
lower_bound_ float
float類型,EM最佳擬合的對數似然(與模型相關的訓練數據)的下限值。
weight_concentration_prior_ tuple or float
每個組分在權重分布上的dirichlet濃度(dirichlet)。類型取決于 weight_concentration_prior_type
濃度越高,中心的質量越大,活性組分越多,而濃度越低,單純形邊緣的質量越大。
weight_concentration_ array-like, shape (n_components,)
每個組分在權重分布上的dirichlet濃度(dirichlet)。
mean_precision_prior_ float
均值分布上的先驗精度(高斯)。控制可以放置工具的范圍。較大的值將聚類均值集中在mean_prior周圍。如果mean_precision_prior設置為None,mean_precision_prior_則設置為1。
mean_precision_ array-like, shape (n_components,)
每個分量在平均分布上的精度(高斯)。
mean_prior_ array-like, shape (n_features,)
均值上的先驗分布(高斯)。
degrees_of_freedom_prior_ float
協方差分布上的自由度數的先驗(Wishart)。
degrees_of_freedom_ array-like, shape (n_components,)
模型中每個組件的自由度數。
covariance_prior_ float or array-like
協方差分布的先驗(Wishart)。形狀取決于covariance_type
(n_features, n_features) if 'full',
(n_features, n_features) if 'tied',
(n_features) if 'diag',
float if 'spherical'

另見

GaussianMixture

有限高斯混合與EM擬合。

參考文獻

1 Bishop, Christopher M. (2006). “Pattern recognition and machine learning”. Vol. 4 No. 4. New York: Springer.

2 Hagai Attias. (2000). “A Variational Bayesian Framework for Graphical Models”. In Advances in Neural Information Processing Systems 12.

3 Blei, David M. and Michael I. Jordan. (2006). “Variational inference for Dirichlet process mixtures”. Bayesian analysis 1.1

方法 說明
fit(X[, y]) 使用EM算法估算模型參數。
fit_predict(X[, y]) 使用X估算模型參數并預測X的標簽。
get_params([deep]) 獲取此估計量的參數。
predict(X) 使用訓練好的模型預測X中數據樣本的標簽。
predict_proba(X) 給定數據,預測每個分量的后驗概率。
sample([n_samples]) 從擬合的高斯分布中生成隨機樣本。
score(X[, y]) 計算給定數據X的每樣本平均對數似然度。
score_samples(X) 計算每個樣本的加權對數概率。
set_params(**params) 設置此估算量的參數。
__init__(*,n_components=1,covariance_type='full',tol=0.001,reg_covar=1e-06, max_iter=100, n_init=1, init_params='kmeans', weight_concentration_prior_type='dirichlet_process', weight_concentration_prior=None, mean_precision_prior=None, mean_prior=None, degrees_of_freedom_prior=None, covariance_prior=None, random_state=None, warm_start=False, verbose=0, verbose_interval=10)

[源碼]

初始化self, 請參閱help(type(self))以獲得準確的說明。

fit(X, y=None)

[源碼]

使用EM算法估算模型參數。

該方法擬合模型n_init時間,并設置模型具有最大似然性或下界的參數。在每次試驗中,該方法都會在E步和M步之間迭代一段max_iter 時間,直到似然性或下界的變化小于tol為止 ,否則ConvergenceWarning提高a。如果warm_startTrue,則將n_init忽略,并在第一次調用時執行一次初始化。連續通話時,訓練從停下來的地方開始。

參數 說明
X array-like, shape (n_samples, n_features)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
self -
fit_predict(X, y=None)

[源碼]

使用X估算模型參數并預測X的標簽。

該方法擬合模型n_init次,并設置模型具有最大似然性或下界的參數。在每次試驗中,該方法都會在E步和M步之間迭代一段max_iter 時間,直到似然性或下界的變化小于 tol為止,否則ConvergenceWarning提高a。擬合后,它將為輸入數據點預測最可能的標簽。

0.20版中的新功能。

參數 說明
X array-like, shape (n_samples, n_features)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
labels array, shape (n_samples,)
組件標簽
get_params(deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算量和作為估算量的所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
predict(X)

[源碼]

使用訓練好的模型預測X中數據樣本的標簽。

參數 說明
X array-like, shape (n_samples, n_features)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
labels array, shape (n_samples,)
組件標簽。
predict_proba(X)

[源碼]

給定數據,預測每個分量的后驗概率。

參數 說明
X array-like, shape (n_samples, n_features)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
resp array, shape (n_samples, n_components)
返回給定每個樣本的模型中每個高斯(狀態)的概率。
sample(n_samples=1)

[源碼]

從擬合的高斯分布中生成隨機樣本。

參數 說明
n_samples int, optional
要生成的樣本數。默認為1。
返回值 說明
X array, shape (n_samples, n_features)
隨機生成的樣本
y array, shape (nsamples,)
組件標簽
score(X, y=None)

[源碼]

計算給定數據X的每樣本平均對數似然度。

參數 說明
X array-like, shape (n_samples, n_dimensions)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
log_likelihood float
給定X的高斯混合的對數似然。
score_samples(X)

[源碼]

計算每個樣本的加權對數概率。

參數 說明
X array-like, shape (n_samples, n_features)
n_features維數據點列表。每行對應一個數據點。
返回值 說明
log_prob array, shape (n_samples,)
在X中記錄每個數據點的概率。
set_params(**params)

[源碼]

設置此估算器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如 pipelines)。后者具有形式的參數, <component>__<parameter>以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估算量參數。
返回值 說明
self object
估計量實例