keras 网络中t-sne可视化应用

import numpy as np
import matplotlib.pyplot as plt
from keras import backend as K
from sklearn import manifold

intermed_tensor_func=K.function([model.layers[0].input],[model.layers[-1].output])
intermed_tensor=intermed_tensor_func([Test_data])[0]

tsne=manifold.TSNE(n_components=2,init='pca',random_state=1000)
intermed_tsne=tsne.fit_transform(intermed_tensor)
print('Origin data dimension is {}.Embedded data dimension is {}'
.format(Test_data[0,:].shape(-1),intermed_tsne.shape[-1]))

plt.figure(figsize=(12,12))
for i in range(len(Test_data)):
	plt.scatter(intermed_tsne[i,0],intermed_tsne[i,1],c=plt.cm.Set1(Test_Y[i]))

你可能感兴趣的:(数据处理)