2017-01-01 48 views
0

我有兩個密集矩陣(titlepara)。我希望使用親和傳播算法對它們進行聚類,然後繪製聚類。關於兩個特徵和繪圖結果的集羣

我已經寫了下面的代碼,哪些集羣基於一個特徵。我怎樣才能適應這兩個功能集羣,然後繪製結果?

import os 
import time 
import string 
import pickle 
import matplotlib.pyplot as plt 
from sklearn.cluster import AffinityPropagation 
from sklearn import metrics 
import matplotlib.pyplot as plt 
from itertools import cycle 

#from sklearn.ensemble import RandomForestClassifier 

#Opens and stores preprocessed data. 
filepath = '...' 
with open((filepath + 'para.dat'), 'rb') as infile: 
    para = pickle.load(infile) 
with open(filepath + 'title.dat', 'rb') as infile: 
    title = pickle.load(infile) 
with open(filepath + 'y.dat', 'rb') as infile: 
    y = pickle.load(infile) 

af = AffinityPropagation().fit(para) 
cluster_centers_indices = af.cluster_centers_indices_ 
labels = af.labels_ 
n_clusters_= len(cluster_centers_indices) 

這是我用這爲執行聚類,由此整個數據集簇和簇的質心形成產生訓練數據集代表的訓練數據集的查詢的主動學習方法的一部分整個數據集。

回答

0

有無數的方法可以做到這一點(但當然只有有限的結果),所以您需要更精確地確定最佳結果。

例如,你可以申請親和力傳播到

alpha * para + (1 - alpha) * title 
+0

已編輯問題以澄清目的。 – user7347576

+0

在這種情況下,它們的權重不相等? – user7347576

+0

他們可能無法比較,所以即使將alpha設置爲0.5,他們也不會產生相同的影響。 –

0

你想要做的是,你有陣列組合成一個大的陣列,使他們都可以聚集在一起,你可以做一個方式是什麼這是通過使用numphy追加庫Exzample:

X = np.append(title, para, axis =0) 
af = AffinityPropagation().fit(X) 

現在,他們結合他們可以聚集找到它們的中心相結合。