Now that the T-sne has been integrated into the Sklearn, the following is an example of a reduced-dimension visualization.
The required documentation Fdata is roughly as follows
3
6
4 5 7 6 23 5
Ftarget roughly as follows
1
1
2
4
This allows you to use the "NumPy loadtxt data format in fact."
#!/usr/bin/python # encoding=utf-8 #-*-Coding:utf-8-* # Toggle Work path import OS import sys os.chdir (os.path.split. Realpath (Sys.argv[0])) [0]) import numpy from numpy import * Import NumPy as NP from sklearn.manifold import Tsne fro M sklearn.datasets import load_iris from sklearn.decomposition import PCA import Matplotlib.pyplot as PLT class Chj_data ( Object): Def __init__ (self,data,target): Self.data=data self.target=target def chj_load_file (fdata,ft
Arget): Data=numpy.loadtxt (Fdata, Dtype=float32) target=numpy.loadtxt (Ftarget, Dtype=int32) print (Data.shape) Print (Target.shape) # pexit () res=chj_data (data,target) return res fdata= "Data/3.txt" ftarget= "data/4.t"
XT "#iris = Load_iris () # using Sklearn's own test file Iris = Chj_load_file (fdata,ftarget) #print (iris.data) #print (iris.target) #exit () X_tsne = Tsne (n_components=2,learning_rate=100). Fit_transform (iris.data) #X_pca = PCA (). Fit_transform ( Iris.data) Print ("finishe!") plt.fiGure (figsize= (6)) #plt. Subplot (121) Plt.scatter (x_tsne[:, 0], x_tsne[:, 1], C=iris.target) #plt. Subplot (122) #
Plt.scatter (x_pca[:, 0], x_pca[:, 1], C=iris.target) Plt.colorbar () plt.show ()
Reference URL
http://blog.sina.com.cn/s/blog_92d2c5e10102w4si.html
http://scikit-learn.org/stable/modules/ generated/sklearn.manifold.tsne.html