简单理解RandomTreesEmbedding(随机森林嵌入)

sklearn.ensemble.RandomTreesEmbedding模块简单介绍

RandomTreesEmbedding是一种利用完全随机树森林算法将原本在低维分布下线性不可分的数据映射到高维空间使其稀疏化,从而线性可分的算法。本质是一种将样本从低维空间映到高维空间的映射。

符号约定 n t r e e n_{tree} ntree为完全随机树数(简单评估器个数), n d e p t h n_{depth} ndepth为树的层数, n s a m p l e n_{sample} nsample为样本数。

输出 n s a m p l e × ( n t r e e × n d e p t h ) n_{sample}\times (n_{tree}\times n_{depth}) nsample×(ntree×ndepth)的2维One-Hot矩阵,其第 ( i , 2 n d e p t h × ( j − 1 ) + k ) , k ⩽ n t r e e (i,2n_{depth}\times (j-1)+k),k\leqslant n_{tree} (i,2ndepth×(j1)+k),kntree个元素意为第 i i i个样本属于\不属于第 j j j棵树的第 k k k个节点。因为这里的树是完全二叉树,左节点和右节点是成对出现的,所以这个矩阵的列也是两列两列的读的。

注意,这恰好构成了样本在 n t r e e × 2 n d e p t h n_{tree}\times 2n_{depth} ntree×2ndepth维空间下的坐标。

>>> from sklearn.ensemble import RandomTreesEmbedding
>>> X = [[0,0], [1,0], [0,1], [-1,0], [0,-1]]
>>> random_trees = RandomTreesEmbedding(
...    n_estimators=5, random_state=0, max_depth=1).fit(X)
>>> X_sparse_embedding = random_trees.transform(X)
>>> X_sparse_embedding.toarray()
array([[0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],
       [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.],
       [0., 1., 0., 1., 0., 1., 0., 1., 0., 1.],
       [1., 0., 1., 0., 1., 0., 1., 0., 1., 0.],
       [0., 1., 1., 0., 1., 0., 0., 1., 1., 0.]])

请注意,最后这一串One-Hot矩阵就是样本在升维后的空间下的坐标,其维数 = 5 × 2 × 1 =5\times 2 \times 1 =5×2×1。类似于流形学习。

用途:这个算法网上写的也不是很多,我找到了一个后来原博客找不到了
1.映射到高维空间、稀疏化使其线性可分(RandomTreesEmbedding+LinearModel)
2.生成新特征,然后喂给线性模型

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值