Github user sethah commented on a diff in the pull request:
https://github.com/apache/spark/pull/15435#discussion_r94616155
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
---
@@ -1095,6 +1131,89 @@ private[classification] class MultiClassSummarizer
extends Serializable {
}
/**
+ * :: Experimental ::
+ * Summary of multi-classification algorithms.
+ *
+ * @param predictions [[DataFrame]] produced by model.transform().
+ * @param predictionCol Name for column of prediction in `predictions`.
+ * @param labelCol Name for column of label in `predictions`.
+ */
+@Experimental
+@Since("2.1.0")
+class MulticlassSummary private[ml] (
+ @transient val predictions: DataFrame,
+ val predictionCol: String,
+ val labelCol: String) extends Serializable {
+
+ @transient private val multinomialMetrics = {
+ new MulticlassMetrics(
+ predictions.select(
+ col(predictionCol),
+ col(labelCol).cast(DoubleType))
+ .rdd.map { case Row(prediction: Double, label: Double) =>
(prediction, label) })
+ }
+
+ /** Returns false positive rate for each label. */
+ @Since("2.1.0")
+ @transient lazy val falsePositiveRateByLabel: Array[Double] = {
+ multinomialMetrics.labels.map(label =>
multinomialMetrics.falsePositiveRate(label))
+ }
+
+ /** Returns precision for each label. */
+ @Since("2.1.0")
+ @transient lazy val precisionByLabel: Array[Double] = {
+ multinomialMetrics.labels.map(label =>
multinomialMetrics.precision(label))
+ }
+
+ /** Returns recall for each label. */
+ @Since("2.1.0")
+ @transient lazy val recallByLabel: Array[Double] = {
+ multinomialMetrics.labels.map(label =>
multinomialMetrics.recall(label))
+ }
+
+ /**
+ * Returns f-measure for each label.
+ * @param beta the beta parameter.
+ */
+ @Since("2.1.0")
+ def fMeasureByLabel(beta: Double): Array[Double] = {
+ multinomialMetrics.labels.map(label =>
multinomialMetrics.fMeasure(label, beta))
+ }
+
+ /** Returns f1-measure for each label. */
+ @Since("2.1.0")
+ @transient lazy val fMeasureByLabel: Array[Double] = fMeasureByLabel(1.0)
+
+ /** Returns accuracy. */
+ @Since("2.1.0")
+ @transient lazy val accuracy: Double = multinomialMetrics.accuracy
+
+ /** Returns weighted false positive rate. */
+ @Since("2.1.0")
+ @transient lazy val weightedFalsePositiveRate: Double
+ = multinomialMetrics.weightedFalsePositiveRate
+
+ /** Returns weighted averaged recall. */
+ @Since("2.1.0")
+ @transient lazy val weightedRecall: Double =
multinomialMetrics.weightedRecall
+
+ /** Returns weighted averaged precision. */
+ @Since("2.1.0")
+ @transient lazy val weightedPrecision: Double =
multinomialMetrics.weightedPrecision
+
+ /**
+ * Returns weighted averaged f-measure.
+ * @param beta the beta parameter.
--- End diff --
Same as above.
---
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]