2017-03-17 64 views
2

我正在嘗試爲Iris數據集(https://archive.ics.uci.edu/ml/datasets/Iris)生成SOM映射的可視化。在自組織映射圖或虹膜數據集中可視化類標籤

我迄今爲止代碼:

from sklearn.datasets import load_iris 
from mvpa2.suite import * 
import pandas as pd 
import numpy as np 

df = pd.read_csv(filepath_or_buffer='data/iris.data', header=None, sep=',') 
df.columns=['sepal_len', 'sepal_wid', 'petal_len', 'petal_wid', 'class'] 
df.dropna(how="all", inplace=True) # drops the empty line at file-end 

# split the data table into feature data x and class labels y 
x = df.ix[:,0:4].values # the first 4 columns are the features 
y = df.ix[:,4].values # the last column is the class label 
t = np.zeros(len(y), dtype=int) 
t[y == 'Iris-setosa'] = 0 
t[y == 'Iris-versicolor'] = 1 
t[y == 'Iris-virginica'] = 2 

som = SimpleSOMMapper((240, 320), 100, learning_rate=0.05) 
som.train(x) 

pl.imshow(som.K, origin='lower') 
mapped = som(x) 

for i, m in enumerate(mapped): 
    pl.text(m[1], m[0], t[i], ha='center', va='center', 
      bbox=dict(facecolor='white', alpha=0.5, lw=0)) 
pl.show() 

產生這種映射:

enter image description here

有什麼辦法可以自定義面板,所以它看起來像這樣的更好? (取自https://github.com/JustGlowing/minisom)?

enter image description here

基本上我想在一個更好的方式來使用一個更好的調色板(也許更少的顏色)和標記類的標籤。

謝謝。

+0

有關如何在Python代碼的問題是題外話這裏。這看起來應該是關於[SO]的主題。如果您等待,我們會嘗試將其遷移到那裏。 – gung

+0

對不起,我不知道哪個地方更合適,因爲人們沒有真正討論SO上的自組織地圖。謝謝 –

回答

1

我會回答我的問題:原來,我忘了切開我的數據:

pl.imshow(som.K[:,:,0], origin='lower') 

現在一切看起來不錯: enter image description here

+0

這是否真的像你提到的那個問題? – Gathide

+0

是的,這正是我想要的。 –

相關問題