import numpy as np
from sklearn.manifold import TSNE
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import umap
import torch
X=torch.load('embeddings.pt') # (19783, 16)
y = np.load('labels.npy')
# reduced_x = TSNE().fit_transform(X)
# plt.figure(figsize=(8, 8))
# sc = plt.scatter(reduced_x[:,0], reduced_x[:,1],c=y)#,cmap='Spectral')#, lw=0, s=40)
# plt.axis('off')
# plt.savefig('tsne-generated.png', dpi=120)
# reduced_x = PCA(n_components=2).fit_transform(X)
# plt.figure(figsize=(8, 8))
# sc = plt.scatter(reduced_x[:,0], reduced_x[:,1],c=y)#,cmap='Spectral')#, lw=0, s=40)
# plt.axis('off')
# plt.savefig('pca-generated.png', dpi=120)
# reduced_x = PCA(n_components=4).fit_transform(X)
# reduced_x = TSNE().fit_transform(reduced_x)
# plt.figure(figsize=(8, 8))
# sc = plt.scatter(reduced_x[:,0], reduced_x[:,1],c=y)#,cmap='Spectral')#, lw=0, s=40)
# plt.axis('off')
# plt.savefig('pca-tsne-generated.png', dpi=120)
reduced_x = PCA(n_components=4).fit_transform(X)
model=umap.UMAP(n_components=2)
reduced_x=model.fit_transform(reduced_x)
plt.figure(figsize=(8, 8))
sc = plt.scatter(reduced_x[:,0], reduced_x[:,1],c=y)#,cmap='Spectral')#, lw=0, s=40)
plt.axis('off')
plt.savefig('umap-generated.png', dpi=120)
标签:plt,fit,tsne,transform,umap,可视化,import,reduced
From: https://www.cnblogs.com/yonggie/p/17805703.html