天天看點

TSNE畫圖TSNE畫圖

TSNE畫圖

2D圖

from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import numpy as np

# 10條資料,每條資料6維
h = np.random.randn(10, 6) 

# 使用PCA降維到2維
tsne = TSNE(n_components=2, init='pca', random_state=0)
result_2D = tsne.fit_transform(h)
# 10條資料中前5條為一類,後五條為一類
s1, s2 = result_2D[:5, :], result_2D[5:, :]
fig = plt.figure()
t1 = plt.scatter(s1[:, 0], s1[:, 1], marker='x', c='r', s=20)  # marker:點符号 c:點顔色 s:點大小
t2 = plt.scatter(s2[:, 0], s2[:, 1], marker='o', c='b', s=20)
plt.xlabel('X')
plt.ylabel('Y')
plt.legend((t1, t2), ('pos', 'neg'))
plt.show()

           
TSNE畫圖TSNE畫圖