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

    https://github.com/apache/spark/pull/12360#discussion_r59580903
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/tree/impl/DecisionTreeMetadata.scala 
---
    @@ -184,15 +185,15 @@ private[spark] object DecisionTreeMetadata extends 
Logging {
           case _ => featureSubsetStrategy
         }
     
    -    val isIntRegex = "^([1-9]\\d*)$".r
    -    val isFractionRegex = "^(0?\\.\\d*[1-9]\\d*|1\\.0+)$".r
         val numFeaturesPerNode: Int = _featureSubsetStrategy match {
           case "all" => numFeatures
           case "sqrt" => math.sqrt(numFeatures).ceil.toInt
           case "log2" => math.max(1, (math.log(numFeatures) / 
math.log(2)).ceil.toInt)
           case "onethird" => (numFeatures / 3.0).ceil.toInt
    -      case isIntRegex(number) => if (BigInt(number) > numFeatures) 
numFeatures else number.toInt
    -      case isFractionRegex(fraction) => (fraction.toDouble * 
numFeatures).ceil.toInt
    +      case RandomForestParams.integerFeatureSubsetStrategy(number) =>
    --- End diff --
    
    I think we should simplify the checks.
    
    ~~~scala
    import scala.util.Try
    
    val numFeaturesPerNode: Int = _featureSubsetStrategy match {
       ...
       case _ =>
         Try(_featureSubsetStrategy.toDouble).toOption match {
           case Some(value) =>
             if (value <= 0.0) {
               throw new IllegalArgumentException(...)
             } else if (value < 1.0) {
               math.ceil(value * numFeatures)
             } else {
               math.ceil(value)
             }
           case None =>
             throw new IllegalArgumentException(...)
         }
    }
    ~~~
    
    See my comment below for the validator.


---
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