【问题标题】:Multidimensional scaling to data in python多维缩放到python中的数据
【发布时间】:2017-04-29 06:33:47
【问题描述】:

我有以下代码将多维缩放应用于名为parkinsonData 的数据样本:

iterations=4
count=0
while(count<iterations):
    mds1=manifold.MDS(n_components=2, max_iter=3000)
    pos=mds1.fit(parkinsonData).embedding_
    plt.scatter(pos[:, 0], pos[:, 1])
    count=count+1

有了这个,我得到了这个 MDS 算法的 4 个不同的图,由于随机种子,它们都是不同的。这些图有不同的颜色,但parkinsonData 有一个名为status 的列有 0 或 1 个值,我想在每个图中用不同的颜色显示这种差异。

比如我想实现:

一个绘图,状态字段中的 0 值使用一种颜色,状态字段中的 1 值使用不同颜色。

第二个绘图,状态字段中的 0 值使用一种颜色,状态字段中的 1 值使用不同颜色。 (两种颜色都与第一个图不同)

第三个图,状态字段中的 0 值使用一种颜色,状态字段中的 1 值使用不同的颜色。 (两种颜色都不同于第一个和第二个图)

第四个图,状态字段中的 0 值使用一种颜色,状态字段中的 1 值使用不同的颜色。 (两种颜色都与第一、二、三图不同)

有人知道如何实现这种预期行为吗?

【问题讨论】:

    标签: python scikit-learn artificial-intelligence multi-dimensional-scaling


    【解决方案1】:

    你可以这样做

    %matplotlib inline
    import matplotlib.pyplot as plt
    
    # example data
    Y = [[ 1 , 2 , 3 ,6], [ 1 , 2 , 3 ,6], [ 1 , 2 , 3 ,6], [ 1 , 2 , 3 ,6]]
    X = [[ 1 , 2 , 4 ,5], [ 1 , 2 , 3 ,6], [ 1 , 2 , 3 ,6], [ 1 , 2 , 3 ,6]]
    status = [[0,1,0,0], [0,0,1,1], [1,1,0,0], [0,1,0,1]]
    
    # create a list of list of unique colors for 4 plots
    my_colors = [['red','green'],['blue','black'],['magenta','grey'],['purple','cyan']]
    
    
    iterations=4
    count=0
    while(count<iterations):
        plt.figure()
        for i,j in enumerate(X):
            plt.scatter(X[count][i],Y[count][i],color = my_colors[count][status[count][i]])
        count=count+1
        plt.show()
    

    结果(我只附加了 2 张图片,但 4 张图片是使用独特的颜色集创建的)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-10
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-05
      • 2011-05-25
      相关资源
      最近更新 更多