Data visualization 在自组织映射图或iris数据集中可视化类标签

Data visualization 在自组织映射图或iris数据集中可视化类标签,data-visualization,python,self-organizing-maps,Data Visualization,Python,Self Organizing Maps,我正在尝试为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', 'sep

我正在尝试为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()
这将生成此映射:

有没有办法自定义调色板,使它看起来更像这个?(摘自)

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


谢谢。

我将回答我自己的问题:结果是我忘了切片数据:

pl.imshow(som.K[:,:,0], origin='lower')
现在一切看起来都很好:

关于如何用Python编写代码的问题在这里是无关紧要的。这看起来应该是关于主题的。如果您稍等,我们将尝试将其迁移到那里。很抱歉,我不知道哪个地方更合适,因为人们并不真正讨论自组织地图。谢谢,这真的像你在问题中提到和想要的吗?是的,这正是我想要的。