精华内容
下载资源
问答
  • sklearn中的降维PCATSNE

    千次阅读 2018-06-22 10:24:25
    同为降维工具,二者的主要区别在于,所在的包不同(也即机制原理不同) from sklearn.decomposition import PCAfrom sklearn.manifold import TSNE因为原理不同,导致,tsne 保留下的属性信息,更具代表性,也即...

    同为降维工具,二者的主要区别在于,

    • 所在的包不同(也即机制和原理不同) 
      • from sklearn.decomposition import PCA
      • from sklearn.manifold import TSNE
    • 因为原理不同,导致,tsne 保留下的属性信息,更具代表性,也即最能体现样本间的差异;
    • TSNE 运行极慢,PCA 则相对较快;

    因此更为一般的处理,尤其在展示(可视化)高维数据时,常常先用 PCA 进行降维,再使用 tsne:

    data_pca = PCA(n_components=50).fit_transform(data)
    data_pca_tsne = TSNE(n_components=2).fit_transform(data_pca)
    
    转载https://blog.csdn.net/lanchunhui/article/details/64923702

    python--sklearn,聚类结果可视化工具TSNE

    详见

    https://www.cnblogs.com/cygalaxy/p/6934197.html

    展开全文
  • sklearn 特征降维利器 —— PCA & TSNE

    万次阅读 2017-03-22 19:00:09
    同为降维工具,二者的主要区别在于, 所在的包不同(也即机制原理不同) from sklearn.decomposition import PCA ...TSNE 运行极慢,PCA 则相对较快; 因此更为一般的处理,尤其在展示(可视化)高维数据时,常

    同为降维工具,二者的主要区别在于,

    • 所在的包不同(也即机制和原理不同)
      • from sklearn.decomposition import PCA
      • from sklearn.manifold import TSNE
    • 因为原理不同,导致,tsne 保留下的属性信息,更具代表性,也即最能体现样本间的差异;
    • TSNE 运行极慢,PCA 则相对较快;

    因此更为一般的处理,尤其在展示(可视化)高维数据时,常常先用 PCA 进行降维,再使用 tsne:

    data_pca = PCA(n_components=50).fit_transform(data)
    data_pca_tsne = TSNE(n_components=2).fit_transform(data_pca)
    

    t-SNE(t-distribution Stochastic Neighbor Embedding)是目前最为流行的高维数据的降维算法。

    t-SNE 成立的前提基于这样的一个假设:我们现实世界观察到的数据集,都在本质上有一种低维的特性(low intrinsic dimensionality),尽管它们嵌入在高维空间中,甚至可以说,高维数据经过降维后,在低维状态下,更能显现其本质特性,这其实也是流形学习(Manifold Learning)的基本思想。

    原始论文请见,论文链接(pdf)

    1. sklearn 仿真

    • import 必要的库;

      import numpy as np
      from numpy import linalg
      from numpy.linalg import norm
      from scipy.spatial.distance import squareform, pdist
      
      # We import sklearn.
      import sklearn
      from sklearn.manifold import TSNE
      from sklearn.datasets import load_digits
      from sklearn.preprocessing import scale
      
      # We'll hack a bit with the t-SNE code in sklearn 0.15.2.
      from sklearn.metrics.pairwise import pairwise_distances
      from sklearn.manifold.t_sne import (_joint_probabilities,
                                          _kl_divergence)
      from sklearn.utils.extmath import _ravel
      # Random state.
      RS = 20150101
      
      # We'll use matplotlib for graphics.
      import matplotlib.pyplot as plt
      import matplotlib.patheffects as PathEffects
      import matplotlib
      %matplotlib inline
      
      # We import seaborn to make nice plots.
      import seaborn as sns
      sns.set_style('darkgrid')
      sns.set_palette('muted')
      sns.set_context("notebook", font_scale=1.5,
                      rc={"lines.linewidth": 2.5})
      
      # We'll generate an animation with matplotlib and moviepy.
      from moviepy.video.io.bindings import mplfig_to_npimage
      import moviepy.editor as mpy
      
    • 加载数据集

      digits = load_digits()
      		# digits.data.shape ⇒ (1797L, 64L)
      
    • 调用 sklearn 工具箱中的 t-SNE 类

      X = np.vstack([digits.data[digits.target==i]
                     for i in range(10)])
      y = np.hstack([digits.target[digits.target==i]
                     for i in range(10)])
      digits_proj = TSNE(random_state=RS).fit_transform(X)
      		# digits_proj:(1797L, 2L),ndarray 类型
      
    • 可视化

      def scatter(x, colors):
          # We choose a color palette with seaborn.
          palette = np.array(sns.color_palette("hls", 10))
      
          # We create a scatter plot.
          f = plt.figure(figsize=(8, 8))
          ax = plt.subplot(aspect='equal')
          sc = ax.scatter(x[:,0], x[:,1], lw=0, s=40,
                          c=palette[colors.astype(np.int)])
          plt.xlim(-25, 25)
          plt.ylim(-25, 25)
          ax.axis('off')
          ax.axis('tight')
      
          # We add the labels for each digit.
          txts = []
          for i in range(10):
              # Position of each label.
              xtext, ytext = np.median(x[colors == i, :], axis=0)
              txt = ax.text(xtext, ytext, str(i), fontsize=24)
              txt.set_path_effects([
                  PathEffects.Stroke(linewidth=5, foreground="w"),
                  PathEffects.Normal()])
              txts.append(txt)
      
          return f, ax, sc, txts
      scatter(digits_proj, y)
      plt.savefig('images/digits_tsne-generated.png', dpi=120)
      

    An illustrated introduction to the t-SNE algorithm

    展开全文
  • TSNE高维向量降维3D可视化

    千次阅读 2019-03-23 11:02:04
    搞深度学习时可能会遇到想可视化神经网络某一层的输出...TSNE和PCA两种方法都可以实现高维向量可视化,两者原理不同,速度也差很多,TSNE会慢一些。 这里主要还是用到了python里的matplotlib库进行图形绘制。 ...

    搞深度学习时可能会遇到想可视化神经网络某一层的输出向量的需求,我最近就遇到了这样的需求,需要对网络的降维结果进行可视化,我这里对3D可视化做一下简单的介绍。主要还是参考了网上很多大神的写法。

    TSNE和PCA两种方法都可以实现高维向量可视化,两者原理不同,速度也差很多,TSNE会慢一些。
    这里主要还是用到了python里的matplotlib库进行图形绘制,就用最简单的MNIST来做说明吧。完整代码

    code
    import tensorflow as tf
    import numpy as np
    from sklearn.manifold import TSNE  # TSNE集成在了sklearn中
    import matplotlib.pylab as plt
    from mpl_toolkits.mplot3d import Axes3D  # 进行3D图像绘制
    
    import input_data  # MNIST的数据操作文件
    
    mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
    saver = tf.train.import_meta_graph('model/model.ckpt.meta')  # tensorflow加载神经网络图结构
    gragh = tf.get_default_graph()
    
    image_input = gragh.get_tensor_by_name('Placeholder:0')  # 获得图中预定义的输入,即MNIST图像
    label_input = gragh.get_tensor_by_name('Placeholder_1:0')  # 获得对应图像的标签
    predict = gragh.get_tensor_by_name('fco/BiasAdd:0')  # 获得网络的输出值
    
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
    
        saver.restore(sess, tf.train.latest_checkpoint("model"))  # tensorflow恢复神经网络参数到当前图
    
        # 方便快速计算,只取训练集前面2000个数据进行可视化。
        pre = sess.run(predict,
                       feed_dict={image_input: mnist.test.images[:2000, :], label_input: mnist.test.labels[:2000, :]})
    
        # TSNE进行降维计算,n_components代表降维维度
        embedded = TSNE(n_components=3).fit_transform(pre)
    
        # 对数据进行归一化操作
        x_min, x_max = np.min(embedded, 0), np.max(embedded, 0)
        embedded = embedded / (x_max - x_min)
    
        # 创建显示的figure
        fig = plt.figure()
        ax = Axes3D(fig)
        # 将数据对应坐标输入到figure中,不同标签取不同的颜色,MINIST共0-9十个手写数字
        ax.scatter(embedded[:, 0], embedded[:, 1], embedded[:, 2],
                   c=plt.cm.Set1(np.argmax(mnist.test.labels[:2000, :], axis=1) / 10.0))
    
        # 关闭了plot的坐标显示
        plt.axis('off')
        plt.show()
    
    
    3D可视化效果图,不同颜色代表不同的数字类别

    在这里插入图片描述

    展开全文
  •   本文使用PCA、ICA、TSNE等降维模型进行了对比实验,分别对原始数据进行降维并可视化展示,然后分别用PCA、ICA、TSNE降维后的数据训练一个简单MLP神经网络用于评估降维的数据质量。最后用三个模型的预测效果进行...

      本文使用PCA、ICA、TSNE等降维模型进行了对比实验,分别对原始数据进行降维并可视化展示,然后分别用PCA、ICA、TSNE降维后的数据训练一个简单MLP神经网络用于评估降维的数据质量。最后用三个模型的预测效果进行了对比和结果的展示。
      本文使用的数据集在本人上传的资源中,链接为mock_kaggle.csv

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import tensorflow as tf
    from sklearn.decomposition import FastICA,PCA
    from sklearn.manifold import TSNE
    from sklearn import preprocessing
    

    取数据

    data=pd.read_csv('mock_kaggle.csv',encoding ='gbk',parse_dates=['datetime'])
    
    data=data.iloc[:,1:]
    
    data
    
    特价 股票 价格
    0 0 4972 1.29
    1 70 4902 1.29
    2 59 4843 1.29
    3 93 4750 1.29
    4 96 4654 1.29
    ... ... ... ...
    932 98 3179 2.39
    933 108 3071 2.39
    934 128 4095 2.39
    935 270 3825 2.39
    936 183 3642 2.39

    937 rows × 3 columns

    标准化

    data_normal = preprocessing.scale(data)
    train_label=data_normal[:900,1]
    test_label=data_normal[901:,1]
    

    PCA降维

    pca = PCA(n_components=2)
    pca_data = pca.fit_transform(data_normal)     #等价于pca.fit(X) pca.transform(X)
    #invX = pca.inverse_transform(X)  #将降维后的数据转换成原始数据
    print(pca.explained_variance_ratio_)#输出降维后的各特征贡献度
    
    [0.38909061 0.3429785 ]
    
    plt.figure(figsize=(12,8))
    plt.title('PCA Components')
    plt.scatter(pca_data[:,0], pca_data[:,1])
    

    在这里插入图片描述

    训练简单神经网络

    pca_train_data=pca_data[:900]
    pca_test_data=pca_data[901:]
    pca_model=tf.keras.Sequential([tf.keras.layers.Dense(10,input_shape=(2,),activation='relu'),
                               tf.keras.layers.Dense(10,activation='relu'),
                               tf.keras.layers.Dense(1)])
    pca_model.summary()#查看模型基本信息
    pca_model.compile(optimizer='adam',loss='mse',metrics=['mape']) #设置优化器和损失函数
    pca_history=pca_model.fit(pca_train_data,train_label,epochs=100) #每个数据训练1000次
    
    Model: "sequential"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    dense (Dense)                (None, 10)                30        
    _________________________________________________________________
    dense_1 (Dense)              (None, 10)                110       
    _________________________________________________________________
    dense_2 (Dense)              (None, 1)                 11        
    =================================================================
    Total params: 151
    Trainable params: 151
    Non-trainable params: 0
    _________________________________________________________________
    Train on 900 samples
    Epoch 1/100
    900/900 [==============================] - 2s 2ms/sample - loss: 0.7850 - mape: 174.4778
    Epoch 2/100
    900/900 [==============================] - 0s 231us/sample - loss: 0.6291 - mape: 203.4696
    Epoch 3/100
    900/900 [==============================] - 0s 184us/sample - loss: 0.5221 - mape: 235.8750
    Epoch 4/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.4389 - mape: 260.7603
    Epoch 5/100
    900/900 [==============================] - 0s 172us/sample - loss: 0.3774 - mape: 280.1786
    Epoch 6/100
    900/900 [==============================] - 0s 184us/sample - loss: 0.3348 - mape: 283.5222
    Epoch 7/100
    900/900 [==============================] - 0s 310us/sample - loss: 0.3014 - mape: 286.3506
    Epoch 8/100
    900/900 [==============================] - 0s 230us/sample - loss: 0.2762 - mape: 291.6097
    Epoch 9/100
    900/900 [==============================] - 0s 234us/sample - loss: 0.2539 - mape: 279.0452
    Epoch 10/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.2364 - mape: 267.8730
    Epoch 11/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.2219 - mape: 254.5653
    Epoch 12/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.2095 - mape: 241.9442
    Epoch 13/100
    900/900 [==============================] - 0s 266us/sample - loss: 0.1987 - mape: 234.5619
    Epoch 14/100
    900/900 [==============================] - 0s 184us/sample - loss: 0.1884 - mape: 225.1507
    Epoch 15/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1811 - mape: 221.8909
    Epoch 16/100
    900/900 [==============================] - 0s 214us/sample - loss: 0.1749 - mape: 205.1877
    Epoch 17/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.1702 - mape: 204.4365
    Epoch 18/100
    900/900 [==============================] - 0s 189us/sample - loss: 0.1649 - mape: 198.4753
    Epoch 19/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.1621 - mape: 205.5184
    Epoch 20/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1590 - mape: 195.3820
    Epoch 21/100
    900/900 [==============================] - 0s 196us/sample - loss: 0.1569 - mape: 197.1003
    Epoch 22/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.1547 - mape: 193.8486
    Epoch 23/100
    900/900 [==============================] - 0s 181us/sample - loss: 0.1543 - mape: 192.1595
    Epoch 24/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.1519 - mape: 192.7433
    Epoch 25/100
    900/900 [==============================] - 0s 169us/sample - loss: 0.1519 - mape: 190.2121
    Epoch 26/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.1508 - mape: 196.8424
    Epoch 27/100
    900/900 [==============================] - 0s 193us/sample - loss: 0.1510 - mape: 187.2915
    Epoch 28/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1489 - mape: 187.9957
    Epoch 29/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1494 - mape: 191.7432
    Epoch 30/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.1485 - mape: 196.7090
    Epoch 31/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1477 - mape: 189.1148
    Epoch 32/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1468 - mape: 193.2476
    Epoch 33/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.1473 - mape: 191.6133
    Epoch 34/100
    900/900 [==============================] - 0s 173us/sample - loss: 0.1464 - mape: 186.4275
    Epoch 35/100
    900/900 [==============================] - 0s 233us/sample - loss: 0.1454 - mape: 190.5075
    Epoch 36/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1450 - mape: 189.6160
    Epoch 37/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1450 - mape: 190.8441
    Epoch 38/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.1449 - mape: 191.0887
    Epoch 39/100
    900/900 [==============================] - 0s 192us/sample - loss: 0.1446 - mape: 195.8095
    Epoch 40/100
    900/900 [==============================] - 0s 203us/sample - loss: 0.1446 - mape: 187.4518
    Epoch 41/100
    900/900 [==============================] - 0s 188us/sample - loss: 0.1441 - mape: 191.2747
    Epoch 42/100
    900/900 [==============================] - 0s 243us/sample - loss: 0.1441 - mape: 191.9978
    Epoch 43/100
    900/900 [==============================] - 0s 217us/sample - loss: 0.1439 - mape: 185.9973
    Epoch 44/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.1446 - mape: 186.2656
    Epoch 45/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.1439 - mape: 179.1912
    Epoch 46/100
    900/900 [==============================] - 0s 217us/sample - loss: 0.1443 - mape: 189.1231
    Epoch 47/100
    900/900 [==============================] - 0s 221us/sample - loss: 0.1446 - mape: 190.8205
    Epoch 48/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.1426 - mape: 197.7570
    Epoch 49/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.1425 - mape: 191.7054
    Epoch 50/100
    900/900 [==============================] - 0s 235us/sample - loss: 0.1424 - mape: 195.1246
    Epoch 51/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1417 - mape: 188.4568
    Epoch 52/100
    900/900 [==============================] - 0s 247us/sample - loss: 0.1422 - mape: 190.8196
    Epoch 53/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1419 - mape: 195.7927
    Epoch 54/100
    900/900 [==============================] - 0s 192us/sample - loss: 0.1421 - mape: 192.0233
    Epoch 55/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1416 - mape: 189.6909
    Epoch 56/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1410 - mape: 189.0969
    Epoch 57/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.1415 - mape: 182.2992
    Epoch 58/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.1412 - mape: 189.5773
    Epoch 59/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1417 - mape: 193.3024
    Epoch 60/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1411 - mape: 188.5672
    Epoch 61/100
    900/900 [==============================] - 0s 248us/sample - loss: 0.1422 - mape: 187.6868
    Epoch 62/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.1424 - mape: 197.4033
    Epoch 63/100
    900/900 [==============================] - 0s 188us/sample - loss: 0.1425 - mape: 189.5185
    Epoch 64/100
    900/900 [==============================] - 0s 216us/sample - loss: 0.1411 - mape: 192.8488
    Epoch 65/100
    900/900 [==============================] - 0s 260us/sample - loss: 0.1413 - mape: 185.5174
    Epoch 66/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.1405 - mape: 189.3971
    Epoch 67/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1407 - mape: 186.0119
    Epoch 68/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.1430 - mape: 187.2527
    Epoch 69/100
    900/900 [==============================] - 0s 233us/sample - loss: 0.1410 - mape: 183.7318
    Epoch 70/100
    900/900 [==============================] - 0s 225us/sample - loss: 0.1409 - mape: 193.7119
    Epoch 71/100
    900/900 [==============================] - 0s 211us/sample - loss: 0.1402 - mape: 186.8175
    Epoch 72/100
    900/900 [==============================] - 0s 204us/sample - loss: 0.1400 - mape: 191.3500
    Epoch 73/100
    900/900 [==============================] - 0s 178us/sample - loss: 0.1396 - mape: 184.2501
    Epoch 74/100
    900/900 [==============================] - 0s 178us/sample - loss: 0.1411 - mape: 191.1308
    Epoch 75/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1399 - mape: 185.8354
    Epoch 76/100
    900/900 [==============================] - 0s 168us/sample - loss: 0.1397 - mape: 191.8246
    Epoch 77/100
    900/900 [==============================] - 0s 181us/sample - loss: 0.1395 - mape: 190.7547
    Epoch 78/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1397 - mape: 188.8087
    Epoch 79/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1399 - mape: 186.0689
    Epoch 80/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.1397 - mape: 189.4801
    Epoch 81/100
    900/900 [==============================] - 0s 163us/sample - loss: 0.1396 - mape: 181.5564
    Epoch 82/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1398 - mape: 187.0418
    Epoch 83/100
    900/900 [==============================] - 0s 178us/sample - loss: 0.1393 - mape: 188.8249
    Epoch 84/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.1419 - mape: 186.9317
    Epoch 85/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.1400 - mape: 194.4677
    Epoch 86/100
    900/900 [==============================] - 0s 167us/sample - loss: 0.1401 - mape: 181.7322
    Epoch 87/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1401 - mape: 190.9029
    Epoch 88/100
    900/900 [==============================] - 0s 172us/sample - loss: 0.1405 - mape: 192.8174
    Epoch 89/100
    900/900 [==============================] - 0s 172us/sample - loss: 0.1400 - mape: 186.8127
    Epoch 90/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.1398 - mape: 188.7201
    Epoch 91/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.1407 - mape: 185.1754
    Epoch 92/100
    900/900 [==============================] - 0s 168us/sample - loss: 0.1397 - mape: 192.7381
    Epoch 93/100
    900/900 [==============================] - 0s 221us/sample - loss: 0.1393 - mape: 186.2105
    Epoch 94/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.1391 - mape: 181.0793
    Epoch 95/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1389 - mape: 190.5739
    Epoch 96/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.1382 - mape: 192.4536
    Epoch 97/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1386 - mape: 182.1012
    Epoch 98/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.1386 - mape: 190.5573
    Epoch 99/100
    900/900 [==============================] - 0s 196us/sample - loss: 0.1379 - mape: 186.4868
    Epoch 100/100
    900/900 [==============================] - 0s 271us/sample - loss: 0.1384 - mape: 189.7631
    

    ICA降维

    # ICA降维
    ica = FastICA(n_components=2)
    ica_data = ica.fit_transform(data_normal)  # 重构信号
    # A_ = ica.mixing_  # 获得估计混合后的矩阵
    
    plt.figure(figsize=(12,8))
    plt.title('ICA Components')
    plt.scatter(ica_data[:,0], ica_data[:,1])
    

    在这里插入图片描述

    训练简单神经网络

    ica_train_data=ica_data[:900]
    ica_test_data=ica_data[901:]
    ica_model=tf.keras.Sequential([tf.keras.layers.Dense(10,input_shape=(2,),activation='relu'),
                               tf.keras.layers.Dense(10,activation='relu'),
                               tf.keras.layers.Dense(1)])
    ica_model.summary()#查看模型基本信息
    ica_model.compile(optimizer='adam',loss='mse',metrics=['mape']) #设置优化器和损失函数
    ica_history=ica_model.fit(ica_train_data,train_label,epochs=100) #每个数据训练1000次
    
    Model: "sequential_1"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    dense_3 (Dense)              (None, 10)                30        
    _________________________________________________________________
    dense_4 (Dense)              (None, 10)                110       
    _________________________________________________________________
    dense_5 (Dense)              (None, 1)                 11        
    =================================================================
    Total params: 151
    Trainable params: 151
    Non-trainable params: 0
    _________________________________________________________________
    Train on 900 samples
    Epoch 1/100
    900/900 [==============================] - 1s 1ms/sample - loss: 0.9873 - mape: 103.0597
    Epoch 2/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.9456 - mape: 110.8891
    Epoch 3/100
    900/900 [==============================] - 0s 170us/sample - loss: 0.9062 - mape: 117.8290
    Epoch 4/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.8612 - mape: 120.4753
    Epoch 5/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.8110 - mape: 122.2516
    Epoch 6/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.7573 - mape: 134.9871
    Epoch 7/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.6952 - mape: 135.3464
    Epoch 8/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.6329 - mape: 152.0235
    Epoch 9/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.5675 - mape: 162.2172
    Epoch 10/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.5150 - mape: 168.6576
    Epoch 11/100
    900/900 [==============================] - 0s 205us/sample - loss: 0.4536 - mape: 201.6551
    Epoch 12/100
    900/900 [==============================] - 0s 196us/sample - loss: 0.4089 - mape: 206.0919
    Epoch 13/100
    900/900 [==============================] - 0s 193us/sample - loss: 0.3707 - mape: 230.9236
    Epoch 14/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.3410 - mape: 248.6063
    Epoch 15/100
    900/900 [==============================] - 0s 192us/sample - loss: 0.3208 - mape: 258.0475
    Epoch 16/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.3083 - mape: 276.5189
    Epoch 17/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.2968 - mape: 287.3281
    Epoch 18/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.2902 - mape: 304.3135
    Epoch 19/100
    900/900 [==============================] - 0s 189us/sample - loss: 0.2842 - mape: 292.3876
    Epoch 20/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.2802 - mape: 294.3054
    Epoch 21/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.2762 - mape: 295.0771
    Epoch 22/100
    900/900 [==============================] - 0s 188us/sample - loss: 0.2723 - mape: 301.5387
    Epoch 23/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.2673 - mape: 296.3002
    Epoch 24/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.2655 - mape: 286.4019
    Epoch 25/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.2650 - mape: 295.7499
    Epoch 26/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.2597 - mape: 296.9456
    Epoch 27/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.2601 - mape: 279.2125
    Epoch 28/100
    900/900 [==============================] - 0s 198us/sample - loss: 0.2533 - mape: 288.8799
    Epoch 29/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.2469 - mape: 287.6161
    Epoch 30/100
    900/900 [==============================] - 0s 179us/sample - loss: 0.2436 - mape: 271.4766
    Epoch 31/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.2377 - mape: 272.0242
    Epoch 32/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.2349 - mape: 269.1444
    Epoch 33/100
    900/900 [==============================] - 0s 181us/sample - loss: 0.2317 - mape: 270.4389
    Epoch 34/100
    900/900 [==============================] - 0s 184us/sample - loss: 0.2291 - mape: 259.8926
    Epoch 35/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.2267 - mape: 255.4664
    Epoch 36/100
    900/900 [==============================] - 0s 189us/sample - loss: 0.2239 - mape: 261.1479
    Epoch 37/100
    900/900 [==============================] - 0s 209us/sample - loss: 0.2250 - mape: 266.7558
    Epoch 38/100
    900/900 [==============================] - 0s 217us/sample - loss: 0.2205 - mape: 264.2413
    Epoch 39/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.2184 - mape: 262.9426
    Epoch 40/100
    900/900 [==============================] - 0s 223us/sample - loss: 0.2140 - mape: 258.2297
    Epoch 41/100
    900/900 [==============================] - 0s 288us/sample - loss: 0.2117 - mape: 252.5215
    Epoch 42/100
    900/900 [==============================] - 0s 221us/sample - loss: 0.2106 - mape: 250.6110
    Epoch 43/100
    900/900 [==============================] - 0s 248us/sample - loss: 0.2076 - mape: 253.7611
    Epoch 44/100
    900/900 [==============================] - 0s 233us/sample - loss: 0.2073 - mape: 256.7436
    Epoch 45/100
    900/900 [==============================] - 0s 205us/sample - loss: 0.2053 - mape: 243.5077
    Epoch 46/100
    900/900 [==============================] - 0s 267us/sample - loss: 0.2019 - mape: 243.2053
    Epoch 47/100
    900/900 [==============================] - 0s 215us/sample - loss: 0.2019 - mape: 248.5658
    Epoch 48/100
    900/900 [==============================] - 0s 238us/sample - loss: 0.1990 - mape: 239.8024
    Epoch 49/100
    900/900 [==============================] - 0s 238us/sample - loss: 0.1977 - mape: 240.7237
    Epoch 50/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.1963 - mape: 228.0875
    Epoch 51/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.1986 - mape: 246.7753
    Epoch 52/100
    900/900 [==============================] - 0s 212us/sample - loss: 0.1927 - mape: 237.7096
    Epoch 53/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1915 - mape: 237.9841
    Epoch 54/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.1912 - mape: 227.1314
    Epoch 55/100
    900/900 [==============================] - 0s 173us/sample - loss: 0.1925 - mape: 232.2966
    Epoch 56/100
    900/900 [==============================] - 0s 295us/sample - loss: 0.1898 - mape: 236.6484
    Epoch 57/100
    900/900 [==============================] - 0s 197us/sample - loss: 0.1880 - mape: 236.1455
    Epoch 58/100
    900/900 [==============================] - 0s 272us/sample - loss: 0.1888 - mape: 237.5421
    Epoch 59/100
    900/900 [==============================] - 0s 222us/sample - loss: 0.1874 - mape: 240.4873
    Epoch 60/100
    900/900 [==============================] - 0s 257us/sample - loss: 0.1879 - mape: 226.1057
    Epoch 61/100
    900/900 [==============================] - 0s 253us/sample - loss: 0.1854 - mape: 227.4727
    Epoch 62/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.1874 - mape: 225.6724
    Epoch 63/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1834 - mape: 227.1784
    Epoch 64/100
    900/900 [==============================] - 0s 221us/sample - loss: 0.1835 - mape: 230.1133
    Epoch 65/100
    900/900 [==============================] - 0s 262us/sample - loss: 0.1825 - mape: 222.8086
    Epoch 66/100
    900/900 [==============================] - 0s 236us/sample - loss: 0.1814 - mape: 217.2498
    Epoch 67/100
    900/900 [==============================] - 0s 223us/sample - loss: 0.1833 - mape: 226.5325
    Epoch 68/100
    900/900 [==============================] - 0s 240us/sample - loss: 0.1808 - mape: 215.9711
    Epoch 69/100
    900/900 [==============================] - 0s 228us/sample - loss: 0.1805 - mape: 222.7063
    Epoch 70/100
    900/900 [==============================] - 0s 197us/sample - loss: 0.1803 - mape: 220.8909
    Epoch 71/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.1791 - mape: 218.5792
    Epoch 72/100
    900/900 [==============================] - 0s 281us/sample - loss: 0.1784 - mape: 215.1091
    Epoch 73/100
    900/900 [==============================] - 0s 248us/sample - loss: 0.1789 - mape: 213.6558
    Epoch 74/100
    900/900 [==============================] - 0s 213us/sample - loss: 0.1782 - mape: 217.4238
    Epoch 75/100
    900/900 [==============================] - 0s 266us/sample - loss: 0.1827 - mape: 243.4462
    Epoch 76/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1766 - mape: 217.2935
    Epoch 77/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1764 - mape: 216.2845
    Epoch 78/100
    900/900 [==============================] - 0s 168us/sample - loss: 0.1773 - mape: 213.9372
    Epoch 79/100
    900/900 [==============================] - 0s 223us/sample - loss: 0.1755 - mape: 218.9747
    Epoch 80/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1774 - mape: 218.7054
    Epoch 81/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1769 - mape: 212.9746
    Epoch 82/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1759 - mape: 216.8962
    Epoch 83/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1749 - mape: 222.6659
    Epoch 84/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1752 - mape: 205.6387
    Epoch 85/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1743 - mape: 211.9823
    Epoch 86/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1737 - mape: 219.6483
    Epoch 87/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1732 - mape: 217.6315
    Epoch 88/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1741 - mape: 217.9983
    Epoch 89/100
    900/900 [==============================] - 0s 166us/sample - loss: 0.1745 - mape: 206.2586
    Epoch 90/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.1731 - mape: 222.3474
    Epoch 91/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.1720 - mape: 212.1967
    Epoch 92/100
    900/900 [==============================] - 0s 166us/sample - loss: 0.1744 - mape: 215.4123
    Epoch 93/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.1752 - mape: 221.3754
    Epoch 94/100
    900/900 [==============================] - 0s 209us/sample - loss: 0.1727 - mape: 222.7617
    Epoch 95/100
    900/900 [==============================] - 0s 306us/sample - loss: 0.1719 - mape: 209.2482
    Epoch 96/100
    900/900 [==============================] - 0s 291us/sample - loss: 0.1716 - mape: 202.8925
    Epoch 97/100
    900/900 [==============================] - 0s 268us/sample - loss: 0.1711 - mape: 220.4949
    Epoch 98/100
    900/900 [==============================] - 0s 212us/sample - loss: 0.1705 - mape: 212.8038
    Epoch 99/100
    900/900 [==============================] - 0s 265us/sample - loss: 0.1736 - mape: 225.6118
    Epoch 100/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.1723 - mape: 221.9312
    

    TSNE降维

    tsne = TSNE(method='exact',init='pca',n_components=2, random_state=0, perplexity=5)
    #learning rate:学习率,表示梯度下降的快慢,默认为200,建议取值在10到1000之间
    #n_iter:迭代次数,默认为1000,自定义设置时应保证大于250
    #perplexity:混乱度,表示t-SNE优化过程中考虑邻近点的多少,默认为30,建议取值在5到50之间
    #method:两种优化方法:barnets_hut和exact。第一种耗时O(NlogN),第二种耗时O(N^2)但是误差小
    #metric:表示向量间距离度量的方式,默认是欧氏距离。如果是precomputed,则输入X是计算好的距离矩阵。也可以是自定义的距离度量函数。
    #init:初始化,默认为random。取值为random为随机初始化,取值为pca为利用PCA进行初始化(常用),取值为numpy数组时必须shape=(n_samples, n_components)
    tsne_data = tsne.fit_transform(data_normal)
    
    tsne_data.shape,data_normal.shape
    
    ((937, 2), (937, 3))
    
    plt.figure(figsize=(12,8))
    plt.title('TSNE Components')
    plt.scatter(tsne_data[:,0], tsne_data[:,1])
    

    在这里插入图片描述

    训练简单神经网络

    tsne_train_data=tsne_data[:900]
    tsne_test_data=tsne_data[901:]
    tsne_model=tf.keras.Sequential([tf.keras.layers.Dense(10,input_shape=(2,),activation='relu'),
                               tf.keras.layers.Dense(10,activation='relu'),
                               tf.keras.layers.Dense(1)])
    tsne_model.summary()#查看模型基本信息
    tsne_model.compile(optimizer='adam',loss='mse',metrics=['mape']) #设置优化器和损失函数
    tsne_history=tsne_model.fit(tsne_train_data,train_label,epochs=100) #每个数据训练1000次
    
    Model: "sequential_2"
    _________________________________________________________________
    Layer (type)                 Output Shape              Param #   
    =================================================================
    dense_6 (Dense)              (None, 10)                30        
    _________________________________________________________________
    dense_7 (Dense)              (None, 10)                110       
    _________________________________________________________________
    dense_8 (Dense)              (None, 1)                 11        
    =================================================================
    Total params: 151
    Trainable params: 151
    Non-trainable params: 0
    _________________________________________________________________
    Train on 900 samples
    Epoch 1/100
    900/900 [==============================] - 1s 2ms/sample - loss: 89.3856 - mape: 6934.5850
    Epoch 2/100
    900/900 [==============================] - 0s 212us/sample - loss: 21.7487 - mape: 3360.4509
    Epoch 3/100
    900/900 [==============================] - 0s 272us/sample - loss: 7.2081 - mape: 2058.5820
    Epoch 4/100
    900/900 [==============================] - 0s 267us/sample - loss: 3.9222 - mape: 1663.4132
    Epoch 5/100
    900/900 [==============================] - 0s 230us/sample - loss: 2.7726 - mape: 1321.7251
    Epoch 6/100
    900/900 [==============================] - 0s 248us/sample - loss: 2.2014 - mape: 1145.6675
    Epoch 7/100
    900/900 [==============================] - 0s 201us/sample - loss: 1.8586 - mape: 1012.2946
    Epoch 8/100
    900/900 [==============================] - 0s 213us/sample - loss: 1.6085 - mape: 903.4532
    Epoch 9/100
    900/900 [==============================] - 0s 303us/sample - loss: 1.3883 - mape: 829.0187
    Epoch 10/100
    900/900 [==============================] - 0s 208us/sample - loss: 1.2411 - mape: 798.7681
    Epoch 11/100
    900/900 [==============================] - 0s 195us/sample - loss: 1.1060 - mape: 750.3655
    Epoch 12/100
    900/900 [==============================] - 0s 271us/sample - loss: 1.0106 - mape: 696.5897
    Epoch 13/100
    900/900 [==============================] - 0s 234us/sample - loss: 0.9510 - mape: 650.1858
    Epoch 14/100
    900/900 [==============================] - 0s 183us/sample - loss: 0.8703 - mape: 652.8735
    Epoch 15/100
    900/900 [==============================] - 0s 227us/sample - loss: 0.8276 - mape: 627.7747
    Epoch 16/100
    900/900 [==============================] - 0s 205us/sample - loss: 0.7819 - mape: 591.9622
    Epoch 17/100
    900/900 [==============================] - 0s 196us/sample - loss: 0.7341 - mape: 603.2118 - loss: 0.7363 - mape: 605.45
    Epoch 18/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.6928 - mape: 566.8422
    Epoch 19/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.6713 - mape: 585.1208
    Epoch 20/100
    900/900 [==============================] - 0s 205us/sample - loss: 0.6247 - mape: 549.8159
    Epoch 21/100
    900/900 [==============================] - 0s 185us/sample - loss: 0.5897 - mape: 532.0855
    Epoch 22/100
    900/900 [==============================] - 0s 192us/sample - loss: 0.5658 - mape: 527.9331
    Epoch 23/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.5446 - mape: 488.4539
    Epoch 24/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.5169 - mape: 468.9429
    Epoch 25/100
    900/900 [==============================] - 0s 207us/sample - loss: 0.5201 - mape: 467.5760
    Epoch 26/100
    900/900 [==============================] - 0s 304us/sample - loss: 0.4877 - mape: 452.7673
    Epoch 27/100
    900/900 [==============================] - 0s 197us/sample - loss: 0.4782 - mape: 440.4234
    Epoch 28/100
    900/900 [==============================] - 0s 319us/sample - loss: 0.4719 - mape: 439.3805
    Epoch 29/100
    900/900 [==============================] - 0s 213us/sample - loss: 0.4486 - mape: 405.8721
    Epoch 30/100
    900/900 [==============================] - ETA: 0s - loss: 0.4335 - mape: 432.51 - 0s 327us/sample - loss: 0.4355 - mape: 420.7079
    Epoch 31/100
    900/900 [==============================] - 0s 202us/sample - loss: 0.4259 - mape: 408.2603
    Epoch 32/100
    900/900 [==============================] - 0s 212us/sample - loss: 0.4334 - mape: 410.5372
    Epoch 33/100
    900/900 [==============================] - 0s 213us/sample - loss: 0.4127 - mape: 385.4236
    Epoch 34/100
    900/900 [==============================] - 0s 269us/sample - loss: 0.3966 - mape: 402.8446
    Epoch 35/100
    900/900 [==============================] - 0s 199us/sample - loss: 0.3908 - mape: 410.7667
    Epoch 36/100
    900/900 [==============================] - 0s 204us/sample - loss: 0.3764 - mape: 368.6591
    Epoch 37/100
    900/900 [==============================] - 0s 191us/sample - loss: 0.3710 - mape: 371.9299
    Epoch 38/100
    900/900 [==============================] - 0s 279us/sample - loss: 0.3618 - mape: 362.1169
    Epoch 39/100
    900/900 [==============================] - 0s 229us/sample - loss: 0.3583 - mape: 383.2825
    Epoch 40/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.3447 - mape: 360.1974
    Epoch 41/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.3384 - mape: 354.0529
    Epoch 42/100
    900/900 [==============================] - 0s 205us/sample - loss: 0.3303 - mape: 353.8742
    Epoch 43/100
    900/900 [==============================] - 0s 246us/sample - loss: 0.3518 - mape: 376.3791
    Epoch 44/100
    900/900 [==============================] - 0s 311us/sample - loss: 0.3161 - mape: 353.5660
    Epoch 45/100
    900/900 [==============================] - 0s 239us/sample - loss: 0.3059 - mape: 345.9633
    Epoch 46/100
    900/900 [==============================] - 0s 219us/sample - loss: 0.3012 - mape: 335.1208
    Epoch 47/100
    900/900 [==============================] - 0s 257us/sample - loss: 0.2983 - mape: 340.1209
    Epoch 48/100
    900/900 [==============================] - 0s 195us/sample - loss: 0.2884 - mape: 318.1566
    Epoch 49/100
    900/900 [==============================] - 0s 235us/sample - loss: 0.2840 - mape: 331.5550
    Epoch 50/100
    900/900 [==============================] - 0s 194us/sample - loss: 0.2825 - mape: 344.0093
    Epoch 51/100
    900/900 [==============================] - 0s 239us/sample - loss: 0.2776 - mape: 320.8491
    Epoch 52/100
    900/900 [==============================] - 0s 225us/sample - loss: 0.2791 - mape: 312.0119
    Epoch 53/100
    900/900 [==============================] - 0s 209us/sample - loss: 0.2723 - mape: 325.9967
    Epoch 54/100
    900/900 [==============================] - 0s 283us/sample - loss: 0.2650 - mape: 299.1724
    Epoch 55/100
    900/900 [==============================] - 0s 249us/sample - loss: 0.2611 - mape: 287.6593
    Epoch 56/100
    900/900 [==============================] - 0s 260us/sample - loss: 0.2663 - mape: 304.5265
    Epoch 57/100
    900/900 [==============================] - 0s 224us/sample - loss: 0.2570 - mape: 288.9542 - loss: 0.2604 - mape: 365.
    Epoch 58/100
    900/900 [==============================] - 0s 239us/sample - loss: 0.2542 - mape: 300.7240
    Epoch 59/100
    900/900 [==============================] - 0s 219us/sample - loss: 0.2481 - mape: 287.3276
    Epoch 60/100
    900/900 [==============================] - 0s 219us/sample - loss: 0.2510 - mape: 305.7006
    Epoch 61/100
    900/900 [==============================] - 0s 226us/sample - loss: 0.2462 - mape: 315.4265
    Epoch 62/100
    900/900 [==============================] - 0s 275us/sample - loss: 0.2400 - mape: 315.1567
    Epoch 63/100
    900/900 [==============================] - 0s 235us/sample - loss: 0.2456 - mape: 271.3877
    Epoch 64/100
    900/900 [==============================] - 0s 217us/sample - loss: 0.2428 - mape: 310.5604
    Epoch 65/100
    900/900 [==============================] - 0s 222us/sample - loss: 0.2348 - mape: 304.9576
    Epoch 66/100
    900/900 [==============================] - 0s 186us/sample - loss: 0.2274 - mape: 277.8430
    Epoch 67/100
    900/900 [==============================] - 0s 201us/sample - loss: 0.2266 - mape: 273.0795
    Epoch 68/100
    900/900 [==============================] - 0s 187us/sample - loss: 0.2298 - mape: 289.7397
    Epoch 69/100
    900/900 [==============================] - 0s 215us/sample - loss: 0.2250 - mape: 276.7233
    Epoch 70/100
    900/900 [==============================] - 0s 195us/sample - loss: 0.2203 - mape: 269.2948
    Epoch 71/100
    900/900 [==============================] - 0s 229us/sample - loss: 0.2177 - mape: 256.3293
    Epoch 72/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.2180 - mape: 263.3174
    Epoch 73/100
    900/900 [==============================] - 0s 173us/sample - loss: 0.2400 - mape: 295.4164
    Epoch 74/100
    900/900 [==============================] - 0s 177us/sample - loss: 0.2255 - mape: 279.1955
    Epoch 75/100
    900/900 [==============================] - 0s 191us/sample - loss: 0.2176 - mape: 274.6373
    Epoch 76/100
    900/900 [==============================] - 0s 172us/sample - loss: 0.2157 - mape: 292.2338
    Epoch 77/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.2119 - mape: 264.9478
    Epoch 78/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.2127 - mape: 269.1001
    Epoch 79/100
    900/900 [==============================] - 0s 195us/sample - loss: 0.2127 - mape: 281.3460
    Epoch 80/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.2055 - mape: 276.5002
    Epoch 81/100
    900/900 [==============================] - 0s 238us/sample - loss: 0.2062 - mape: 279.3807
    Epoch 82/100
    900/900 [==============================] - 0s 166us/sample - loss: 0.2129 - mape: 290.9121
    Epoch 83/100
    900/900 [==============================] - 0s 162us/sample - loss: 0.2110 - mape: 290.7337
    Epoch 84/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.2045 - mape: 272.8240
    Epoch 85/100
    900/900 [==============================] - 0s 175us/sample - loss: 0.2034 - mape: 296.3637
    Epoch 86/100
    900/900 [==============================] - 0s 176us/sample - loss: 0.1994 - mape: 261.6485
    Epoch 87/100
    900/900 [==============================] - 0s 180us/sample - loss: 0.1970 - mape: 289.5106
    Epoch 88/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.1983 - mape: 287.4521
    Epoch 89/100
    900/900 [==============================] - 0s 178us/sample - loss: 0.2053 - mape: 290.1107
    Epoch 90/100
    900/900 [==============================] - 0s 174us/sample - loss: 0.1981 - mape: 307.7013
    Epoch 91/100
    900/900 [==============================] - 0s 232us/sample - loss: 0.2053 - mape: 299.0280
    Epoch 92/100
    900/900 [==============================] - 0s 171us/sample - loss: 0.2096 - mape: 316.3831
    Epoch 93/100
    900/900 [==============================] - 0s 182us/sample - loss: 0.2034 - mape: 303.2004
    Epoch 94/100
    900/900 [==============================] - 0s 188us/sample - loss: 0.2196 - mape: 262.1139
    Epoch 95/100
    900/900 [==============================] - 0s 193us/sample - loss: 0.1936 - mape: 325.1552
    Epoch 96/100
    900/900 [==============================] - 0s 197us/sample - loss: 0.1936 - mape: 303.9213
    Epoch 97/100
    900/900 [==============================] - 0s 181us/sample - loss: 0.1921 - mape: 288.6425
    Epoch 98/100
    900/900 [==============================] - 0s 168us/sample - loss: 0.1920 - mape: 313.0998
    Epoch 99/100
    900/900 [==============================] - 0s 173us/sample - loss: 0.1954 - mape: 305.5129
    Epoch 100/100
    900/900 [==============================] - 0s 172us/sample - loss: 0.1889 - mape: 314.0016
    

    对比评估

    #模型评估
    pca_model.evaluate(pca_test_data,test_label)
    ica_model.evaluate(ica_test_data,test_label)
    tsne_model.evaluate(tsne_test_data,test_label)
    
    36/1 [========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================] - 0s 8ms/sample - loss: 0.6366 - mape: 146.9983
    36/1 [========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================] - 0s 4ms/sample - loss: 0.6447 - mape: 155.4730
    36/1 [========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================] - 0s 4ms/sample - loss: 0.2164 - mape: 292.4103
    
    
    
    
    
    [0.3441612786716885, 292.4103]
    
    plt.figure(figsize=(10,5))
    pca_history.history.keys() #查看history中存储了哪些参数
    plt.subplot(1,3,1)
    plt.title("PCA")
    plt.plot(pca_history.epoch,pca_history.history.get('loss')) #画出随着epoch增大loss的变化图
    ica_history.history.keys() #查看history中存储了哪些参数
    plt.subplot(1,3,2)
    plt.title("ICA")
    plt.plot(ica_history.epoch,ica_history.history.get('loss')) #画出随着epoch增大loss的变化图
    plt.subplot(1,3,3)
    plt.title("TSNE")
    plt.plot(tsne_history.epoch,tsne_history.history.get('loss')) #画出随着epoch增大loss的变化图
    plt.show()
    

    在这里插入图片描述

    展开全文
  • t-SNE和PCA都是可以用来对数据进行降维的,然后python中可以调用对应的包进行实现。 t-SNE(from sklearn.manifold import TSNE) pca(from sklearn.decomposition import PCA) 开了一个技术交流的公众号,...
  • 由于数据集很大,如果我试图一次性处理整个数据,我会遇到内存错误,我会尝试将它们分成块,然后一次转换一个块,如下所示:tsne = manifold.TSNE(n_components=2, perplexity=30, init='pca'...
  • sklearn.manifold.TSNE实现 t-SNE 的降维可视化 文章目录sklearn.manifold.TSNE实现 t-SNE 的降维可视化1. 介绍2. 代码示例3. sklearn.manifold.TSNE的参数介绍参数默认值attributes 1. 介绍 t-SNE 可以将高维...
  • 从SNE到t-SNE再到LargeVis http://bindog.github.io/blog/2016/06/04/from-sne-to-tsne-to-largevis/ t-SNE和PCA介绍 https://www.jianshu.com/p/8c20b975a174
  • Embedding Projector

    千次阅读 2019-06-20 22:01:25
    Embedding Projector 是一款embedding 可视化化的工具,通过特定的降维算法如PCA,T-sne将原始数据降维到三维空间,我只需要导入我们的数据就可以可视化,非常方便,当然,你也可以使用sklearn中的tsne和PCA+...
  • 情感分类 情感分类是情感分类的项目。(以Yelp审查为输入) 资料资源 什么是新的 3.1 探索其他数字特征(而不是仅文本...使用TSNE和PCA探索单词表示 1.1 使用tf-idf创建情感分类 建立和调整LinearSVC模型。 建立和调
  • t-SNELDA PCA的学习

    2018-04-16 17:27:00
    t-SNE 可以看这篇文章: http://bindog.github.io/blog/2016/06/04/from-sne-to-tsne-to-largevis/ LDA可以看这篇文章: ... ...LDA是有标注的,PCA是无标注的,只考虑协方差的。 之前有篇文...
  • ythonista 数据科学家 Elior Cohen 近日在 Medium 上发文解读了最常见的三大降维技术:PCA、t-SNE 自编码器。为了帮助理解,他还为其中每种相关算法编写了代码(也发布在了 GitHub 上)。机器之心对本文进行了编译...
  • t-SNE(t-distributed stochastic neighborembedding)是用于降维的一种无监督机器学习算法,由 Laurens van der Maaten Geoffrey Hinton在08年提出。t-SNE 作为一种非线性降维算法,非常适用于高维数据降维到2维...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。01 为什么...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。一、为什么...
  • 最近看了一些经典的降维算法,发现网上的资料大部分都不提供源代码,同时个人觉得通过代码理解算法是最有效的一种方式,因此决定自己整理实现一些常见降维算法的代码。(github上不止止有代码,还有相应的资料,...
  • 很容易想到就是降维(PCA等)了。这里使用更高效的T-SNE流行学习法。如果你想深究,可以看看这个博主的教程写得非常详细,还有其他降维方法。如果你想学我这样大概了解一下就行了,那就可以跳过。怎么才能简单画出二维...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。01 为什么...
  • PCA-and-T-SNE-源码

    2021-04-02 20:00:09
    PCA和T-SNE 此数据取自Kaggle(从Kaggle下载的MNIST数据集: ://www.kaggle.com/c/digit-recognizer/data) 在这里,我只是想看看幕后发生的事情以及两者之间的区别 这只是减少尺寸的一个例子。 先决条件(线性代数...
  • 关于降维的学习主要分为五类:PCA、LDA、LLE、tSNE、ISOMAP .降维的作用:(为什么会有这些作用?) (1)降低时间的复杂度空间复杂度 (2)节省了提取不必要特征的开销 (3)去掉数据集中夹杂的噪音 (4)较简单...
  • 异常点检测 前文讲到tsne在高维度数据有着绝对...t-SNE和PCA降维后都有异常点,我们试着来分析分析,这些异常点如何检测以及通过这些点来判断降维的效果。 常见的检测异常点有4种异常点检测方法,One-Class SVM(一分类
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。一、为什么...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。01 为什么...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。01 为...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。01 为什么...
  • from sklearn import manifold # t-SNE 倾向于保存局部特征,训练较慢 for i in range(listLength): ... tsne = manifold.TSNE(n_components=2, init='pca', random_state=501) X_tsne = tsne.fit_transform.
  • 组织着色的GTEx数据集(1000个随机基因)的3D表示形式(UMAP,TSNEPCA): CVAE当前的重建质量,取决于组织。 基于: 对VAE方差损失论文: , , 项目进度: 基准模型创建 评估潜在空间中的均值,绝对差...
  • 这里有个 GitHub 项目整理了使用 Python 实现了 11 种经典的数据抽取(数据降维)算法,包括:PCA、LDA、MDS、LLE、TSNE 等,并附有相关资料、展示效果;非常适合机器学习初学者刚刚入坑数据挖掘的小伙伴。 为...

空空如也

空空如也

1 2 3
收藏数 53
精华内容 21
关键字:

tsne和pca