Github user manishamde commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2125#discussion_r16932280
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/tree/impl/DTStatsAggregator.scala 
---
    @@ -0,0 +1,208 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.mllib.tree.impl
    +
    +import org.apache.spark.mllib.tree.impurity._
    +
    +/**
    + * DecisionTree statistics aggregator.
    + * This holds a flat array of statistics for a set of (nodes, features, 
bins)
    + * and helps with indexing.
    + */
    +private[tree] class DTStatsAggregator(
    +    metadata: DecisionTreeMetadata,
    +    val numNodes: Int) extends Serializable {
    +
    +  /**
    +   * [[ImpurityAggregator]] instance specifying the impurity type.
    +   */
    +  val impurityAggregator: ImpurityAggregator = metadata.impurity match {
    +    case Gini => new GiniAggregator(metadata.numClasses)
    +    case Entropy => new EntropyAggregator(metadata.numClasses)
    +    case Variance => new VarianceAggregator()
    +    case _ => throw new IllegalArgumentException(s"Bad impurity parameter: 
${metadata.impurity}")
    +  }
    +
    +  /**
    +   * Number of elements (Double values) used for the sufficient statistics 
of each bin.
    +   */
    +  val statsSize: Int = impurityAggregator.statsSize
    +
    +  val numFeatures: Int = metadata.numFeatures
    +
    +  /**
    +   * Number of bins for each feature.  This is indexed by the feature 
index.
    +   */
    +  val numBins: Array[Int] = metadata.numBins
    +
    +  /**
    +   * Indicator for each feature of whether that feature is an unordered 
feature.
    +   * TODO: Is Array[Boolean] any faster?
    +   */
    +  def isUnordered(featureIndex: Int): Boolean = 
metadata.isUnordered(featureIndex)
    +
    +  /**
    +   * Offset for each feature for calculating indices into the [[allStats]] 
array.
    +   */
    +  private val featureOffsets: Array[Int] = {
    +    def featureOffsetsCalc(total: Int, featureIndex: Int): Int = {
    +      if (isUnordered(featureIndex)) {
    +        total + 2 * numBins(featureIndex)
    --- End diff --
    
    Would the factor of 2 for unordered categorical feature be more suitable in 
the numBins calculation in the DecisionTreeMetaData class?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to