2025-1-10-sklearn学习(36、37) 数据集转换-无监督降维+随机投影 沙上并禽 ...

打印 上一主题 下一主题

主题 1028|帖子 1028|积分 3084

sklearn学习(36、37) 数据集转换-无监督降维+随机投影

文章参考网站:
https://sklearn.apachecn.org/

https://scikit-learn.org/stable/
sklearn学习(36) 数据集转换-无监督降维

假如你的特性数目很多, 在监督步调之前, 可以通过无监督的步调来淘汰特性. 很多的 无监督学习 方法实现了一个名为 transform 的方法, 它可以用来降低维度. 下面我们将讨论大量使用这种模式的两个具体示例.
   Pipelining 非监督数据约简和监督估计器可以链接起来。 请看 Pipeline: 链式评估器.
  36.1 PCA: 主成份分析

decomposition.PCA 寻找能够捕获原始特性的差异的特性的组合. 请参阅 分解成分中的信号(矩阵分解问题).
   示例 * Faces recognition example using eigenfaces and SVMs
  36.2 随机投影

模块: random_projection 提供了几种用于通过随机投影淘汰数据的工具. 请参阅文档的相关部门: 随机投影.
   示例 * The Johnson-Lindenstrauss bound for embedding with random projections
  36.3 特性聚集

cluster.FeatureAgglomeration 应用 层次聚类 将行为类似的特性分组在一起.
   示例 * Feature agglomeration vs. univariate selection * Feature agglomeration
  特性缩放
  

  • 请注意,假如功能具有明显不同的缩放或统计属性,则 cluster.FeatureAgglomeration 可能无法捕获相关特性之间的关系.使用一个 preprocessing.StandardScaler 可以在这些 设置中使用.
sklearn学习(37) 数据集转换-随机投影

sklearn.random_projection 模块实现了一个简单且高效率的计算方式来淘汰数据维度,通过捐躯肯定的精度(作为附加变量)来加速处理时间及更小的模子尺寸。 这个模子实现了两类无布局化的随机矩阵: Gaussian random matrix 和 sparse random matrix.
随机投影矩阵的维度和分布是受控制的,以是可以保存恣意两个数据集的距离。因此随机投影适用于基于距离的方法。
   参考资料:
  

  • Sanjoy Dasgupta. 2000. Experiments with random projection. In Proceedings of the Sixteenth conference on Uncertainty in artificial intelligence (UAI‘00), Craig Boutilier and Moisés Goldszmidt (Eds.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA, 143-151.
  • Ella Bingham and Heikki Mannila. 2001. Random projection in dimensionality reduction: applications to image and text data. In Proceedings of the seventh ACM SIGKDD international conference on Knowledge discovery and data mining (KDD ‘01). ACM, New York, NY, USA, 245-250.
37.1 Johnson-Lindenstrauss 辅助定理

支撑随机投影效率的主要理论成果是Johnson-Lindenstrauss lemma (quoting Wikipedia):
   在数学中,johnson - lindenstrauss 引理是一种将高维的点从高维到低维欧几里得空间的低失真嵌入的方案。 引理阐释了高维空间下的一小部门的点集可以内嵌到非常低维的空间,这种方式下点之间的距离几乎全部被保留。 内嵌所用到的映射至少符合 Lipschitz 条件,乃至可以被当做正交投影。
  有了样本数目, sklearn.random_projection.johnson_lindenstrauss_min_dim 会保守估计随机子空间的最小大小来包管随机投影导致的变形在肯定范围内:
  1. >>> from sklearn.random_projection import johnson_lindenstrauss_min_dim
  2. >>> johnson_lindenstrauss_min_dim(n_samples=1e6, eps=0.5)
  3. 663
  4. >>> johnson_lindenstrauss_min_dim(n_samples=1e6, eps=[0.5, 0.1, 0.01])
  5. array([    663,   11841, 1112658])
  6. >>> johnson_lindenstrauss_min_dim(n_samples=[1e4, 1e5, 1e6], eps=0.1)
  7. array([ 7894,  9868, 11841])`
复制代码

   示例:
  

  • 检察 The Johnson-Lindenstrauss bound for embedding with random projections 里面有Johnson-Lindenstrauss引理的理论阐明和使用希罕随机矩阵的经验验证。
   参考资料:
  

  • Sanjoy Dasgupta and Anupam Gupta, 1999. An elementary proof of the Johnson-Lindenstrauss Lemma.
37.2 高斯随机投影

The sklearn.random_projection.GaussianRandomProjection 通过将原始输入空间投影到随机天生的矩阵(该矩阵的组件由以下分布中抽取):                                    N                         (                         0                         ,                                   1                                       n                                           c                                  o                                  m                                  p                                  o                                  n                                  e                                  n                                  t                                  s                                                       )                              N(0, \frac{1}{n_{components}})                  N(0,ncomponents​1​) 降低维度。
以下小片段演示了任何使用高斯随机投影转换器:
  1. >>> import numpy as np
  2. >>> from sklearn import random_projection
  3. >>> X = np.random.rand(100, 10000)
  4. >>> transformer = random_projection.GaussianRandomProjection()
  5. >>> X_new = transformer.fit_transform(X)
  6. >>> X_new.shape
  7. (100, 3947)
复制代码
37.3 希罕随机矩阵

sklearn.random_projection.SparseRandomProjection 使用希罕随机矩阵,通过投影原始输入空间来降低维度。
希罕矩阵可以替换高斯随机投影矩阵来包管相似的嵌入质量,且内存使用率更高、投影数据的计算更快。
假如我们界说 s = 1 / density, 随机矩阵的元素由下式抽取。
                                                                                           {                                                                                                                             −                                                                                                s                                                                                   n                                                                components                                                                                                                                                                                                                                                                                                  1                                                       /                                                       2                                                       s                                                                                                                                                                0                                                                                                                  with probability                                                                                                                                     1                                                       −                                                       1                                                       /                                                       s                                                                                                                                                                                   +                                                                                                s                                                                                   n                                                                components                                                                                                                                                                                                                                                                                                  1                                                       /                                                       2                                                       s                                                                                                                                                                \begin{split}\left\{ \begin{array}{c c l} -\sqrt{\frac{s}{n_{\text{components}}}} & & 1 / 2s\\ 0 &\text{with probability} & 1 - 1 / s \\ +\sqrt{\frac{s}{n_{\text{components}}}} & & 1 / 2s\\ \end{array} \right.\end{split}                     ⎩                       ⎨                       ⎧​−ncomponents​s​                              ​0+ncomponents​s​                              ​​with probability​1/2s1−1/s1/2s​​
其中                                              n                            components                                       n_{\text{components}}                  ncomponents​ 是投影后的子空间大小。 默认非零元素的浓密度设置为最小浓密度,该值由Ping Li et al.:推荐,根据公式:                                    1                         /                                              n                               features                                                 1 / \sqrt{n_{\text{features}}}                  1/nfeatures​            ​ 计算。
以下小片段演示了怎样使用希罕随机投影转换器:
  1. >>> import numpy as np
  2. >>> from sklearn import random_projection
  3. >>> X = np.random.rand(100,10000)
  4. >>> transformer = random_projection.SparseRandomProjection()
  5. >>> X_new = transformer.fit_transform(X)
  6. >>> X_new.shape
  7. (100, 3947)
复制代码
  参考资料:
  

  • D. Achlioptas. 2003. Database-friendly random projections: Johnson-Lindenstrauss with binary coins. Journal of Computer and System Sciences 66 (2003) 671–687
  • Ping Li, Trevor J. Hastie, and Kenneth W. Church. 2006. Very sparse random projections. In Proceedings of the 12th ACM SIGKDD international conference on Knowledge discovery and data mining (KDD ‘06). ACM, New York, NY, USA, 287-296.

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

乌市泽哥

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表