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

    https://github.com/apache/spark/pull/14643#discussion_r75290480
  
    --- 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 --
    
    Or, a simpler take is this: if thresholds are just meant to provide a 
minimum class probability, then the logic should simply be to choose the class 
with the highest probability that also exceeds its threshold. What about that?


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