You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by WeichenXu123 <gi...@git.apache.org> on 2017/12/12 08:19:05 UTC

[GitHub] spark pull request #18390: [SPARK-21178][ML] Add support for label specific ...

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

    https://github.com/apache/spark/pull/18390#discussion_r156292467
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/evaluation/MulticlassClassificationEvaluator.scala ---
    @@ -38,17 +38,39 @@ class MulticlassClassificationEvaluator @Since("1.5.0") (@Since("1.5.0") overrid
       @Since("1.5.0")
       def this() = this(Identifiable.randomUID("mcEval"))
     
    +  /**
    +   * param for specific label value for metric to be used in evaluation (supports
    +   *  Double values for metric `"f1"`, `"precision"`, `"recall"`, `"tpr"`, `"fpr"`)
    +   * @group param
    +   */
    +  val labelValue: Param[Double] = {
    +    new DoubleParam(this, "labelValue", "specific labelValue for metric to be used in evaluation")
    +  }
    +
    +  /** @group getParam */
    +  def getLabelValue: Double = $(labelValue)
    +
    +  /** @group setParam */
    +  def setLabelValue(labelClass: Double): this.type = set(labelValue, labelClass)
    +
       /**
        * param for metric name in evaluation (supports `"f1"` (default), `"weightedPrecision"`,
    -   * `"weightedRecall"`, `"accuracy"`)
    +   * `"weightedRecall"`, `"accuracy"` and with labelValue `"f1"`, `"precision"`, `"recall"`,
    +   * `"tpr"`, `"fpr"`)
        * @group param
        */
       @Since("1.5.0")
       val metricName: Param[String] = {
    -    val allowedParams = ParamValidators.inArray(Array("f1", "weightedPrecision",
    -      "weightedRecall", "accuracy"))
    -    new Param(this, "metricName", "metric name in evaluation " +
    -      "(f1|weightedPrecision|weightedRecall|accuracy)", allowedParams)
    +
    +    val allowedParams: String => Boolean = { (p: String) =>
    +      if (isSet(labelValue)) {
    +        ParamValidators.inArray(MulticlassClassificationEvaluator.labelOptions)(p)
    +      } else ParamValidators.inArray(MulticlassClassificationEvaluator.weightedOptions)(p)
    +    }
    --- End diff --
    
    If we set `metricName` first, and then set `labelValue`, then it escape the check here. Does it need also add check for `labelValue` param ?


---

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