私はscikit-学ぶディリクレ過程ガウス混合モデルを実装するために使用しています:Scikit-LearnのDPGMMの冗長コンポーネントを正しく削除する方法は?
https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/mixture/dpgmm.py http://scikit-learn.org/stable/modules/generated/sklearn.mixture.BayesianGaussianMixture.html
それはweight_concentration_prior_type = 'dirichlet_process'
に設定されているデフォルトとsklearn.mixture.BayesianGaussianMixture()
である、です。ユーザがクラスタ「k」の数を先験的に設定するk-meansとは対照的に、DPGMMはクラスタ数の事前分布としてDirichlet Processを有する無限混合モデルである。
私のDPGMMモデルは、一貫して正確なクラスタ数をn_components
として出力します。ここで説明したように、これに対処するための正しい方法はpredict(X)
で「冗長コンポーネントを削減」することです:
Scikit-Learn's DPGMM fitting: number of components?
しかし、にリンクされている例では、実際に冗長コンポーネントを削除しての「正しい」数が表示されませんデータ内のクラスタ。むしろ、単に正しい数のクラスタをプロットします。
http://scikit-learn.org/stable/auto_examples/mixture/plot_gmm.html
ユーザーはどのように実際には配列べきこれらのコンポーネントを冗長コンポーネントを削除し、出力できますか?これは冗長クラスタを削除する "公式" /唯一の方法ですか?
は、ここに私のコードです:
>>> import pandas as pd
>>> import numpy as np
>>> import random
>>> from sklearn import mixture
>>> X = pd.read_csv(....) # my matrix
>>> X.shape
(20000, 48)
>>> dpgmm3 = mixture.BayesianGaussianMixture(n_components = 20, weight_concentration_prior_type='dirichlet_process', max_iter = 1000, verbose = 2)
>>> dpgmm3.fit(X) # Fitting the DPGMM model
>>> labels = dpgmm3.predict(X) # Generating labels after model is fitted
>>> max(labels)
>>> np.unique(labels) #Number of lab els == n_components specified above
array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19])
#Trying with a different n_components
>>> dpgmm3_1 = mixture.BayesianGaussianMixture(weight_concentration_prior_type='dirichlet_process', max_iter = 1000) #not specifying n_components
>>> dpgmm3_1.fit(X)
>>> labels_1 = dpgmm3_1.predict(X)
>>> labels_1
array([0, 0, 0, ..., 0, 0, 0]) #All were classified under the same label
#Trying with n_components = 7
>>> dpgmm3_2 = mixture.BayesianGaussianMixture(n_components = 7, weight_concentration_prior_type='dirichlet_process', max_iter = 1000)
>>> dpgmm3_2.fit()
>>> labels_2 = dpgmm3_2.predict(X)
>>> np.unique(labels_2)
array([0, 1, 2, 3, 4, 5, 6]) #number of labels == n_components
ありがとう、@ogrisel。 APIにいくつかのコメントを追加すると便利かもしれません。 DPGMMを使用する私の唯一の動機は、「先験的にクラスターの数を指定する必要のないアルゴリズムを試してみたいです」ということでした。 DPGMMでは、私たちが作業している仮定がガウスから引き出されるという(無理なく)受け入れています。準自動化された方法がありますか? – EB2127
'weights_'がゼロに非常に近いコンポーネントは実際にはモデルによって無視されます。したがって、実際には、混合物中の成分の数の上限を指定するだけでよく、DP-GMMアルゴリズムは必要でない成分を使用しません(以前の方法に従う)。 – ogrisel
私はちょっと混乱しています。 "DP-GMMアルゴリズムは、(前によると)必要のないコンポーネントを使用しません"これは私が上で行ったことではありませんか?私はそのデータに3〜6個のクラスタを期待しています。私は 'n_components' = 7を設定し、私は7つのクラスタを取得します。私は 'n_components' = 20を設定し、私は20のクラスタを取得します。私は 'n_components' = 30を設定し、私は30のクラスタを取得します。 – EB2127