from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import numpy as np
def plot_embedding(data, label):
_min, _max = np.min(data, 0), np.max(data, 0)
data = (data - _min) / (_max - _min)
for i in range(data.shape[0]):
plt.text(data[i, 0], data[i, 1], str(label[i]),
color=plt.cm.tab10(label[i]),
fontdict={'weight': 'bold', 'size': 9})
plt.show()
feature = "xxx" # numpy.ndarray, 如(1000,256)
y_test = "" # numpy.ndarray, 如(1000,)
tsne = TSNE(n_components=2, init='pca', random_state=0)
tsne_feature = tsne.fit_transform(feature)
plot_embedding(tsne_feature, y_test)
TSNE 降维 可视化脚本
猜你喜欢
转载自blog.csdn.net/hymn1993/article/details/126061206
今日推荐
周排行