多模态多类别数据可视化

多模态多类别数据可视化

from time import time
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
from sklearn import (manifold, datasets, decomposition, ensemble, random_projection)
import pickle
import os

def plot_embedding_2d(X, y, title=None):
    #坐标缩放到[0,1]区间
    x_min, x_max = np.min(X,axis=0), np.max(X,axis=0)
    X = (X - x_min) / (x_max - x_min)
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    color=['#FFB6C1','#DC143C', '#9400D3', '#0000FF', '#00FFFF', '#2F4F4F', '#008B8B', '#00FA9A', '#00FF7F','#7FFF00']
    for i in range(X.shape[0]):
    	if i<1000:
            ax.text(X[i, 0], X[i, 1],'+',color=color[y[i]],fontdict={'weight': 'bold', 'size': 8})
    	else:
            ax.text(X[i, 0], X[i, 1],'*',color=color[y[i]],fontdict={'weight': 'bold', 'size': 8})
    if title is not None:
        plt.title(title)

data = pickle.load(open(os.path.join('./end.pkl'), 'rb'))
#data['X'].shape=(2000,10),data['y'].shape=(2000,)
print("Computing t-SNE embedding")
tsne = manifold.TSNE(n_components=2, init='pca', random_state=0)
t0 = time()
X_tsne = tsne.fit_transform(data['data'])
print(X_tsne.shape)
plot_embedding_2d(X_tsne[:,0:2], data['label'], "visualization result")

plt.show()

你可能感兴趣的:(深度学习通用代码,多模态多类别数据可视化)