imatiach-msft commented on a change in pull request #17084:
[SPARK-24103][ML][MLLIB] ML Evaluators should use weight column - added weight
column for binary classification evaluator
URL: https://github.com/apache/spark/pull/17084#discussion_r257111457
##########
File path:
mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala
##########
@@ -68,21 +74,33 @@ class BinaryClassificationEvaluator @Since("1.4.0")
(@Since("1.4.0") override va
@Since("1.2.0")
def setLabelCol(value: String): this.type = set(labelCol, value)
+ /** @group setParam */
+ @Since("3.0.0")
+ def setWeightCol(value: String): this.type = set(weightCol, value)
+
setDefault(metricName -> "areaUnderROC")
@Since("2.0.0")
override def evaluate(dataset: Dataset[_]): Double = {
val schema = dataset.schema
SchemaUtils.checkColumnTypes(schema, $(rawPredictionCol), Seq(DoubleType,
new VectorUDT))
SchemaUtils.checkNumericType(schema, $(labelCol))
+ if (isDefined(weightCol)) {
+ SchemaUtils.checkNumericType(schema, $(weightCol))
+ }
// TODO: When dataset metadata has been implemented, check
rawPredictionCol vector length = 2.
- val scoreAndLabels =
- dataset.select(col($(rawPredictionCol)),
col($(labelCol)).cast(DoubleType)).rdd.map {
- case Row(rawPrediction: Vector, label: Double) => (rawPrediction(1),
label)
- case Row(rawPrediction: Double, label: Double) => (rawPrediction,
label)
+ val scoreAndLabelsWithWeights =
+ dataset.select(col($(rawPredictionCol)),
col($(labelCol)).cast(DoubleType),
+ if (!isDefined(weightCol) || $(weightCol).isEmpty) lit(1.0)
Review comment:
to confirm, just the formatting needs to be changed? done!
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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]