我正在尝试为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()
产生这种映射:
有什么办法可以自定义面板,所以它看起来像这样的更好? (取自https://github.com/JustGlowing/minisom)?
基本上我想在一个更好的方式来使用一个更好的调色板(也许更少的颜色)和标记类的标签。
谢谢。
有关如何在Python代码的问题是题外话这里。这看起来应该是关于[SO]的主题。如果您等待,我们会尝试将其迁移到那里。 – gung
对不起,我不知道哪个地方更合适,因为人们没有真正讨论SO上的自组织地图。谢谢 –