可视化自组织地图或虹膜数据集中的类标签

时间:2017-03-17 10:50:18

标签: data-visualization python self-organizing-maps

我正在尝试为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

基本上我试图使用更好的调色板(可能用更少的颜色)并以更好的方式标记类标签。

谢谢。

1 个答案:

答案 0 :(得分:2)

我将回答我自己的问题:事实证明我忘了分割数据:

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

现在一切都很好看: enter image description here