srowen commented on a change in pull request #26135: [SPARK-29489][ML][PySpark]
ml.evaluation support log-loss
URL: https://github.com/apache/spark/pull/26135#discussion_r335585953
##########
File path:
mllib/src/main/scala/org/apache/spark/mllib/evaluation/MulticlassMetrics.scala
##########
@@ -237,4 +239,38 @@ class MulticlassMetrics @Since("1.1.0")
(predictionAndLabels: RDD[_ <: Product])
*/
@Since("1.1.0")
lazy val labels: Array[Double] = tpByClass.keys.toArray.sorted
+
+ /**
+ * Returns the logLoss, aka logistic loss or cross-entropy loss.
+ * @param eps LogLoss is undefined for p=0 or p=1, so probabilities are
+ * clipped to max(eps, min(1 - eps, p)).
+ */
+ @Since("3.0.0")
+ def logLoss(eps: Double = 1e-15): Double = {
+ require(eps > 0 && eps < 0.5, s"eps must be in range (0, 0.5), but got
$eps")
+ val loss1 = - math.log(eps)
+ val loss2 = - math.log(1 - eps)
Review comment:
`- math.log1p(-eps)`? because eps is going to be very small
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]