2016-04-26 94 views
0

我有一個小問題,在python中使用t-SNETSNE在sklearn python

予取一小數據集:

A = np.matrix([[0.2, 0.3, 0.6, 0.8], 
       [0.2, 0.25, 0.55, 0.85], 
       [0.2, 0.3, 0.6, 0.8], 
       [0.64, 0.8, 0.2, 0.2], 
       [0.65, 0.8, 0.2, 0.2], 
       [0.65, 0.75, 0.2, 0.15], 
       [0.7, 0.8, 0.2, 0.2]]) 

然後,我在其上運行的叔SNE,用這個命令:

tsne = manifold.TSNE(n_components=2,random_state=0, metric=Distance) 

這裏,Distance是一個函數,它有兩個陣列輸入,計算它們之間的距離並返回距離。 此功能有效。如果更改我的值,我可以看到輸出發生了變化。

def Distance(X,Y): 
    Result = spatial.distance.euclidean(X,Y) 
    return Result 

但是,可視化並沒有改變使用t-sne ...和可視化不尊重我的點之間的距離。

如果我刪除指標:

tsne = manifold.TSNE(n_components=2,random_state=0) 

它仍然給我相同的結果...

enter image description here

你有什麼辦法呢?

回答

0

這是因爲默認metriceuclidean。所以實際上,與默認設置相比,你並沒有改變任何東西。您可以在here處看到默認參數。 我也有複製並粘貼在這裏:

class sklearn.manifold.TSNE(n_components=2, perplexity=30.0, early_exaggeration=4.0, learning_rate=1000.0, n_iter=1000, n_iter_without_progress=30, min_grad_norm=1e-07, metric='euclidean', init='random', verbose=0, random_state=None, method='barnes_hut', angle=0.5)