Python uses Tsne to reduce dimension __python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.