-
from sklearn.manifold import TSNE import numpy as np import matplotlib.pyplot as plt data = np.load("_for_tsne_multi_gc.npy", allow_pickle=True) tsne_exp_name = "multi_(gc)" tsne_data = TSNE(n_components = 2).fit_transform(data.item().get('data')) plt.scatter(tsne_data[:, 0], tsne_data[:, 1], c = data.item().get('gt_label')[:], s = 3) plt.xlim(tsne_data[:, 0].min(), tsne_data[:, 0].max()) # 최소, 최대 plt.ylim(tsne_data[:, 1].min(), tsne_data[:, 1].max()) # 최소, 최대 plt.xlabel('t-SNE attribute1') # x축 이름 plt.ylabel('t-SNE attribute2') # y축 이름 plt.show() # 그래프 출력 plt.savefig(f"./{tsne_exp_name}.png", dpi = 600)
from sklearn.manifold import TSNE import numpy as np import matplotlib.pyplot as plt import seaborn as sns import pandas as pd data = np.load("_for_tsne_multi_sp.npy", allow_pickle=True) tsne_exp_name = "multi_(sp)" #import pdb; pdb.set_trace() #data = {} #data['data'] = np.random.rand(30, 128) #data['gt_label'] = np.random.randint(0, 20, size = (30, 1)) tsne_data = TSNE(n_components = 2).fit_transform(data.item().get('data')) #tsne_data = TSNE(n_components = 2).fit_transform(data['data']) import pdb; pdb.set_trace() df = pd.DataFrame({'t-SNE attribute1' :tsne_data[:, 0], 't-SNE attribute2':tsne_data[:, 1],'label' : np.squeeze(data.item().get('gt_label')[:])}) palette = sns.color_palette(n_colors = 20) sns.scatterplot(data = df, x = 't-SNE attribute1', y = 't-SNE attribute2', hue = 'label', palette = palette, size = 1) plt.legend(bbox_to_anchor=(1.02, 10), loc='upper left', borderaxespad=0) plt.show() # 그래프 출력 plt.savefig(f"./{tsne_exp_name}.png", dpi = 600)