3、親和力傳播
親和力傳播包括找到一組最能概括數(shù)據(jù)的范例。
我們設(shè)計了一種名為“親和傳播”的方法,它作為兩對數(shù)據(jù)點之間相似度的輸入度量。在數(shù)據(jù)點之間交換實值消息,直到一組高質(zhì)量的范例和相應(yīng)的群集逐漸出現(xiàn)
—源自:《通過在數(shù)據(jù)點之間傳遞消息》2007。
它是通過 AffinityPropagation 類實現(xiàn)的,要調(diào)整的主要配置是將“ 阻尼 ”設(shè)置為0.5到1,甚至可能是“首選項”。
下面列出了完整的示例。
# 親和力傳播聚類
from numpy import unique
from numpy import where
from sklearn.datasets import make_classification
from sklearn.cluster import AffinityPropagation
from matplotlib import pyplot
# 定義數(shù)據(jù)集
X, _ = make_classification(n_samples=1000,
n_features=2,
n_informative=2,
n_redundant=0,
n_clusters_per_class=1,
random_state=4)
# 定義模型
model = AffinityPropagation(damping=0.9)
# 匹配模型
model.fit(X)
# 為每個示例分配一個集群
yhat = model.predict(X)
# 檢索唯一群集
clusters = unique(yhat)
# 為每個群集的樣本創(chuàng)建散點圖
for cluster in clusters:
# 獲取此群集的示例的行索引
row_ix = where(yhat == cluster)
# 創(chuàng)建這些樣本的散布
pyplot.scatter(X[row_ix, 0], X[row_ix, 1])
# 繪制散點圖
pyplot.show()
運行該示例符合訓(xùn)練數(shù)據(jù)集上的模型,并預(yù)測數(shù)據(jù)集中每個示例的群集。然后創(chuàng)建一個散點圖,并由其指定的群集著色。在這種情況下,我無法取得良好的結(jié)果。

圖:數(shù)據(jù)集的散點圖,具有使用親和力傳播識別的聚類
4、聚合聚類
聚合聚類涉及合并示例,直到達(dá)到所需的群集數(shù)量為止。它是層次聚類方法的更廣泛類的一部分,通過 AgglomerationClustering 類實現(xiàn)的,主要配置是“ n _ clusters ”集,這是對數(shù)據(jù)中的群集數(shù)量的估計,例如2。下面列出了完整的示例。
# 聚合聚類
from numpy import unique
from numpy import where
from sklearn.datasets import make_classification
from sklearn.cluster import AgglomerativeClustering
from matplotlib import pyplot
# 定義數(shù)據(jù)集
X, _ = make_classification(n_samples=1000,
n_features=2,
n_informative=2,
n_redundant=0,
n_clusters_per_class=1,
random_state=4)
# 定義模型
model = AgglomerativeClustering(n_clusters=2)
# 模型擬合與聚類預(yù)測
yhat = model.fit_predict(X)
# 檢索唯一群集
clusters = unique(yhat)
# 為每個群集的樣本創(chuàng)建散點圖
for cluster in clusters:
# 獲取此群集的示例的行索引
row_ix = where(yhat == cluster)
# 創(chuàng)建這些樣本的散布
pyplot.scatter(X[row_ix, 0], X[row_ix, 1])
# 繪制散點圖
pyplot.show()
運行該示例符合訓(xùn)練數(shù)據(jù)集上的模型,并預(yù)測數(shù)據(jù)集中每個示例的群集。然后創(chuàng)建一個散點圖,并由其指定的群集著色。在這種情況下,可以找到一個合理的分組。

圖:使用聚集聚類識別出具有聚類的數(shù)據(jù)集的散點圖
5、BIRCH
BIRCH 聚類( BIRCH 是平衡迭代減少的縮寫,聚類使用層次結(jié)構(gòu))包括構(gòu)造一個樹狀結(jié)構(gòu),從中提取聚類質(zhì)心。
BIRCH 遞增地和動態(tài)地群集傳入的多維度量數(shù)據(jù)點,以嘗試?yán)每捎觅Y源(即可用內(nèi)存和時間約束)產(chǎn)生最佳質(zhì)量的聚類。
—源自:《 BIRCH :1996年大型數(shù)據(jù)庫的高效數(shù)據(jù)聚類方法》
它是通過 Birch 類實現(xiàn)的,主要配置是“ threshold ”和“ n _ clusters ”超參數(shù),后者提供了群集數(shù)量的估計。下面列出了完整的示例。
# birch聚類
from numpy import unique
from numpy import where
from sklearn.datasets import make_classification
from sklearn.cluster import Birch
from matplotlib import pyplot
# 定義數(shù)據(jù)集
X, _ = make_classification(n_samples=1000,
n_features=2,
n_informative=2,
n_redundant=0,
n_clusters_per_class=1,
random_state=4)
# 定義模型
model = Birch(threshold=0.01, n_clusters=2)
# 適配模型
model.fit(X)
# 為每個示例分配一個集群
yhat = model.predict(X)
# 檢索唯一群集
clusters = unique(yhat)
# 為每個群集的樣本創(chuàng)建散點圖
for cluster in clusters:
# 獲取此群集的示例的行索引
row_ix = where(yhat == cluster)
# 創(chuàng)建這些樣本的散布
pyplot.scatter(X[row_ix, 0], X[row_ix, 1])
# 繪制散點圖
pyplot.show()
運行該示例符合訓(xùn)練數(shù)據(jù)集上的模型,并預(yù)測數(shù)據(jù)集中每個示例的群集。然后創(chuàng)建一個散點圖,并由其指定的群集著色。在這種情況下,可以找到一個很好的分組。

圖:使用BIRCH聚類確定具有聚類的數(shù)據(jù)集的散點圖
-
代碼
+關(guān)注
關(guān)注
30文章
4927瀏覽量
72502 -
數(shù)據(jù)分析
+關(guān)注
關(guān)注
2文章
1494瀏覽量
35808 -
python
+關(guān)注
關(guān)注
56文章
4849瀏覽量
89227
發(fā)布評論請先 登錄
一種基于聚類和競爭克隆機(jī)制的多智能體免疫算法
基于MCL與Chameleon的混合聚類算法
一種改進(jìn)的BIRCH算法聚類方法
Python無監(jiān)督學(xué)習(xí)的幾種聚類算法包括K-Means聚類,分層聚類等詳細(xì)概述
如何在python中安裝和使用頂級聚類算法?
一種自適應(yīng)的關(guān)聯(lián)融合聚類算法

10種聚類算法和Python代碼2
評論