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

    https://github.com/apache/spark/pull/14643#discussion_r74732778
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/ProbabilisticClassifier.scala
 ---
    @@ -201,11 +201,18 @@ abstract class ProbabilisticClassificationModel[
           probability.argmax
         } else {
           val thresholds: Array[Double] = getThresholds
    -      val scaledProbability: Array[Double] =
    -        probability.toArray.zip(thresholds).map { case (p, t) =>
    -          if (t == 0.0) Double.PositiveInfinity else p / t
    -        }
    -      Vectors.dense(scaledProbability).argmax
    +
    +      if (thresholds.contains(0.0)) {
    +        val indices = thresholds.zipWithIndex.filter(_._1 == 0.0).map(_._2)
    +        val values = indices.map(probability.apply)
    +        Vectors.sparse(numClasses, indices, values).argmax
    +      } else {
    +        val scaledProbability: Array[Double] =
    +          probability.toArray.zip(thresholds).map { case (p, t) =>
    +            if (t == 0.0) Double.PositiveInfinity else p / t
    --- End diff --
    
    You don't need the check for 0.0 in this case right?
    
    I see the logic of the change, but I wonder what the motivation is for 
computing a ratio of probabilities here to begin with? I wonder if K-L 
divergence makes sense here instead:  `p*math.log(p/t)  +  
(1-p)*math.log((1-p)/(1-t))`  
    
    @holdenk I believe you added this bit in 
https://github.com/zhengruifeng/spark/commit/5a23213c148bfe362514f9c71f5273ebda0a848a#diff-4a7c1a2a6f2706d045b694f6d7a054f1R201
 ?
    
    As you can see that formula would imply that t > 0 and t < 1. t == 0 means 
"always predict this", and t == 1 means "never predict this". t == 1 is easy 
enough to filter out from consideration, though maybe args checking should 
catch the case that all thresholds are 1 earlier on.
    
    t == 0 is valid if it's true of just one class. That too can be checked 
when it's specified. If that's the case, of course the class to predict is 
clear. Otherwise K-L applies.
    
    I wonder if it's worth expanding scope to consider this?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to