《Spark MLlib 机器学习》细节解释(持续更新)

1、        P220

对该段文字的解决:

得到最大bin 数量后,求最大split 数量。对于无序特征,split = bin 数目/2;对于有序特征,split = bin 数目–1。

 

其中有读者问到:对于无序特征,split = bin 数目/2这个的由来,解释如下:

 

1)首先计算numBins:

        // 当前的特征数量小于m值,则认为无序

        if (numCategories <=maxCategoriesForUnorderedFeature) {//无序时

          unorderedFeatures.add(featureIndex)

          numBins(featureIndex) = numUnorderedBins(numCategories)

        } else {//有序时

          numBins(featureIndex) = numCategories

        }

根据以上可知,无序时numBins = numUnorderedBins(numCategories)

其中numUnorderedBins函数如下:

    /**

   * Given the arity of a categorical feature(arity = number of categories),

   * return the number of bins for the featureif it is to be treated as an unordered feature.

   * There is 1 split for every partitioning ofcategories into 2 disjoint, non-empty sets;

   * there are math.pow(2, arity - 1) - 1 suchsplits.

   * Each split has 2 corresponding bins.

   * 解释:一次划分会有2bins,好比,切西瓜,一刀下去,分成2

   */

  def numUnorderedBins(arity: Int): Int = 2 * ((1 << arity - 1) - 1)

 

根据公式:numBins = 2*math.pow(2,arity - 1) – 1

 

2)根据numBins计算numSplits:

 

  def numSplits(featureIndex: Int): Int = if(isUnordered(featureIndex)) {

    numBins(featureIndex) >> 1

  } else {

    numBins(featureIndex) - 1

  }

 

根据公式:numSplits = numBins/2= math.pow(2, arity - 1) – 1

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值