> 文章列表 > FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略

FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略

FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略

FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略

目录

基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例

# 1、定义数据集

# 2、数据预处理/特征工程

# T1、二维可视化

# 2.1、初始化T-SNE模型

# 2.2、转换数据

# 2.3、可视化结果并标注数据点标签

# T1、添加颜色条及其对应类别

# T2、对图内的数据点加注标签

# T2、三维可视化

# 2.1、初始化T-SNE模型

# 2.2、转换数据

# 2.3、可视化结果并标注数据点标签


相关文章
FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略
FE之TSNE:基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例之详细攻略实现代码

基于MNIST手写数字数据集利用T-SNE/TSNE方法实现高维数据集可视化应(二维可视化和三维可视化)应用案例

# 1、定义数据集

digits {'data': array([[ 0.,  0.,  5., ...,  0.,  0.,  0.],[ 0.,  0.,  0., ..., 10.,  0.,  0.],[ 0.,  0.,  0., ..., 16.,  9.,  0.],...,[ 0.,  0.,  1., ...,  6.,  0.,  0.],[ 0.,  0.,  2., ..., 12.,  0.,  0.],[ 0.,  0., 10., ..., 12.,  1.,  0.]]), 'target': array([0, 1, 2, ..., 8, 9, 8]), 'frame': None, 'feature_names': ['pixel_0_0', 'pixel_0_1', 'pixel_0_2', 'pixel_0_3', 'pixel_0_4', 'pixel_0_5', 'pixel_0_6', 'pixel_0_7', 'pixel_1_0', 'pixel_1_1', 'pixel_1_2', 'pixel_1_3', 'pixel_1_4', 'pixel_1_5', 'pixel_1_6', 'pixel_1_7', 'pixel_2_0', 'pixel_2_1', 'pixel_2_2', 'pixel_2_3', 'pixel_2_4', 'pixel_2_5', 'pixel_2_6', 'pixel_2_7', 'pixel_3_0', 'pixel_3_1', 'pixel_3_2', 'pixel_3_3', 'pixel_3_4', 'pixel_3_5', 'pixel_3_6', 'pixel_3_7', 'pixel_4_0', 'pixel_4_1', 'pixel_4_2', 'pixel_4_3', 'pixel_4_4', 'pixel_4_5', 'pixel_4_6', 'pixel_4_7', 'pixel_5_0', 'pixel_5_1', 'pixel_5_2', 'pixel_5_3', 'pixel_5_4', 'pixel_5_5', 'pixel_5_6', 'pixel_5_7', 'pixel_6_0', 'pixel_6_1', 'pixel_6_2', 'pixel_6_3', 'pixel_6_4', 'pixel_6_5', 'pixel_6_6', 'pixel_6_7', 'pixel_7_0', 'pixel_7_1', 'pixel_7_2', 'pixel_7_3', 'pixel_7_4', 'pixel_7_5', 'pixel_7_6', 'pixel_7_7'], 'target_names': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), 'images': array([[[ 0.,  0.,  5., ...,  1.,  0.,  0.],[ 0.,  0., 13., ..., 15.,  5.,  0.],[ 0.,  3., 15., ..., 11.,  8.,  0.],...,[ 0.,  4., 11., ..., 12.,  7.,  0.],[ 0.,  2., 14., ..., 12.,  0.,  0.],[ 0.,  0.,  6., ...,  0.,  0.,  0.]],[[ 0.,  0.,  0., ...,  5.,  0.,  0.],[ 0.,  0.,  0., ...,  9.,  0.,  0.],[ 0.,  0.,  3., ...,  6.,  0.,  0.],...,[ 0.,  0.,  1., ...,  6.,  0.,  0.],[ 0.,  0.,  1., ...,  6.,  0.,  0.],[ 0.,  0.,  0., ..., 10.,  0.,  0.]],[[ 0.,  0.,  0., ..., 12.,  0.,  0.],[ 0.,  0.,  3., ..., 14.,  0.,  0.],[ 0.,  0.,  8., ..., 16.,  0.,  0.],...,[ 0.,  9., 16., ...,  0.,  0.,  0.],[ 0.,  3., 13., ..., 11.,  5.,  0.],[ 0.,  0.,  0., ..., 16.,  9.,  0.]],...,[[ 0.,  0.,  1., ...,  1.,  0.,  0.],[ 0.,  0., 13., ...,  2.,  1.,  0.],[ 0.,  0., 16., ..., 16.,  5.,  0.],...,[ 0.,  0., 16., ..., 15.,  0.,  0.],[ 0.,  0., 15., ..., 16.,  0.,  0.],[ 0.,  0.,  2., ...,  6.,  0.,  0.]],[[ 0.,  0.,  2., ...,  0.,  0.,  0.],[ 0.,  0., 14., ..., 15.,  1.,  0.],[ 0.,  4., 16., ..., 16.,  7.,  0.],...,[ 0.,  0.,  0., ..., 16.,  2.,  0.],[ 0.,  0.,  4., ..., 16.,  2.,  0.],[ 0.,  0.,  5., ..., 12.,  0.,  0.]],[[ 0.,  0., 10., ...,  1.,  0.,  0.],[ 0.,  2., 16., ...,  1.,  0.,  0.],[ 0.,  0., 15., ..., 15.,  0.,  0.],...,[ 0.,  4., 16., ..., 16.,  6.,  0.],[ 0.,  8., 16., ..., 16.,  8.,  0.],[ 0.,  1.,  8., ..., 12.,  1.,  0.]]]), 
'DESCR': ".. _digits_dataset:\\n\\nOptical recognition of handwritten digits dataset\\n--------------------------------------------------\\n\\n**Data Set Characteristics:**\\n\\n    :Number of Instances: 1797\\n    :Number of Attributes: 64\\n    :Attribute Information: 8x8 image of integer pixels in the range 0..16.\\n    :Missing Attribute Values: None\\n    :Creator: E. Alpaydin (alpaydin '@' boun.edu.tr)\\n    :Date: July; 1998\\n\\nThis is a copy of the test set of the UCI ML hand-written digits datasets\\nhttps://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits\\n\\nThe data set contains images of hand-written digits: 10 classes where\\neach class refers to a digit.\\n\\nPreprocessing programs made available by NIST were used to extract\\nnormalized bitmaps of handwritten digits from a preprinted form. From a\\ntotal of 43 people, 30 contributed to the training set and different 13\\nto the test set. 32x32 bitmaps are divided into nonoverlapping blocks of\\n4x4 and the number of on pixels are counted in each block. This generates\\nan input matrix of 8x8 where each element is an integer in the range\\n0..16. This reduces dimensionality and gives invariance to small\\ndistortions.\\n\\nFor info on NIST preprocessing routines, see M. D. Garris, J. L. Blue, G.\\nT. Candela, D. L. Dimmick, J. Geist, P. J. Grother, S. A. Janet, and C.\\nL. Wilson, NIST Form-Based Handprint Recognition System, NISTIR 5469,\\n1994.\\n\\n.. topic:: References\\n\\n  - C. Kaynak (1995) Methods of Combining Multiple Classifiers and Their\\n    Applications to Handwritten Digit Recognition, MSc Thesis, Institute of\\n    Graduate Studies in Science and Engineering, Bogazici University.\\n  - E. Alpaydin, C. Kaynak (1998) Cascading Classifiers, Kybernetika.\\n  - Ken Tang and Ponnuthurai N. Suganthan and Xi Yao and A. Kai Qin.\\n    Linear dimensionalityreduction using relevance weighted LDA. School of\\n    Electrical and Electronic Engineering Nanyang Technological University.\\n    2005.\\n  - Claudio Gentile. A New Approximate Maximal Margin Classification\\n    Algorithm. NIPS. 2000.\\n"}
target_names [0 1 2 3 4 5 6 7 8 9]

# 2、数据预处理/特征工程

# T1、二维可视化

# 2.1、初始化T-SNE模型

# 2.2、转换数据

X_tsne_2d [[ -5.449044  -68.44699  ][ 12.961729   20.65787  ][ 11.528878   -4.492914 ]...[  3.2276514   2.8702545][-24.402897  -14.898608 ][ -0.2628215  -2.336792 ]]

# 2.3、可视化结果并标注数据点标签

# T1、添加颜色条及其对应类别

# T2、对图内的数据点加注标签

# T2、三维可视化

# 2.1、初始化T-SNE模型

# 2.2、转换数据

X_tsne_3d [[20.30162    -1.9624434   5.3154817 ][-2.3172603   0.04484846 -8.948228  ][-8.027827   -7.9570465   0.39129657]...[-6.2633376  -2.5445085  -1.985671  ][ 0.77245     0.33451074  8.497464  ][-7.104447   -2.531409    2.4231515 ]]

# 2.3、可视化结果并标注数据点标签