diff options
Diffstat (limited to 'mllib/src/main/scala')
4 files changed, 43 insertions, 7 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala b/mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala index 08df2919a8..1fe3abaca8 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/evaluation/BinaryClassificationEvaluator.scala @@ -17,7 +17,7 @@ package org.apache.spark.ml.evaluation -import org.apache.spark.annotation.Experimental +import org.apache.spark.annotation.{Experimental, Since} import org.apache.spark.ml.param._ import org.apache.spark.ml.param.shared._ import org.apache.spark.ml.util.{Identifiable, SchemaUtils} @@ -30,10 +30,12 @@ import org.apache.spark.sql.types.DoubleType * :: Experimental :: * Evaluator for binary classification, which expects two input columns: rawPrediction and label. */ +@Since("1.2.0") @Experimental -class BinaryClassificationEvaluator(override val uid: String) +class BinaryClassificationEvaluator @Since("1.4.0") (@Since("1.4.0") override val uid: String) extends Evaluator with HasRawPredictionCol with HasLabelCol { + @Since("1.2.0") def this() = this(Identifiable.randomUID("binEval")) /** @@ -41,6 +43,7 @@ class BinaryClassificationEvaluator(override val uid: String) * Default: areaUnderROC * @group param */ + @Since("1.2.0") val metricName: Param[String] = { val allowedParams = ParamValidators.inArray(Array("areaUnderROC", "areaUnderPR")) new Param( @@ -48,12 +51,15 @@ class BinaryClassificationEvaluator(override val uid: String) } /** @group getParam */ + @Since("1.2.0") def getMetricName: String = $(metricName) /** @group setParam */ + @Since("1.2.0") def setMetricName(value: String): this.type = set(metricName, value) /** @group setParam */ + @Since("1.5.0") def setRawPredictionCol(value: String): this.type = set(rawPredictionCol, value) /** @@ -61,13 +67,16 @@ class BinaryClassificationEvaluator(override val uid: String) * @deprecated use [[setRawPredictionCol()]] instead */ @deprecated("use setRawPredictionCol instead", "1.5.0") + @Since("1.2.0") def setScoreCol(value: String): this.type = set(rawPredictionCol, value) /** @group setParam */ + @Since("1.2.0") def setLabelCol(value: String): this.type = set(labelCol, value) setDefault(metricName -> "areaUnderROC") + @Since("1.2.0") override def evaluate(dataset: DataFrame): Double = { val schema = dataset.schema SchemaUtils.checkColumnType(schema, $(rawPredictionCol), new VectorUDT) @@ -87,10 +96,12 @@ class BinaryClassificationEvaluator(override val uid: String) metric } + @Since("1.5.0") override def isLargerBetter: Boolean = $(metricName) match { case "areaUnderROC" => true case "areaUnderPR" => true } + @Since("1.4.1") override def copy(extra: ParamMap): BinaryClassificationEvaluator = defaultCopy(extra) } diff --git a/mllib/src/main/scala/org/apache/spark/ml/evaluation/Evaluator.scala b/mllib/src/main/scala/org/apache/spark/ml/evaluation/Evaluator.scala index 13bd3307f8..0f22cca3a7 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/evaluation/Evaluator.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/evaluation/Evaluator.scala @@ -17,7 +17,7 @@ package org.apache.spark.ml.evaluation -import org.apache.spark.annotation.DeveloperApi +import org.apache.spark.annotation.{DeveloperApi, Since} import org.apache.spark.ml.param.{ParamMap, Params} import org.apache.spark.sql.DataFrame @@ -25,6 +25,7 @@ import org.apache.spark.sql.DataFrame * :: DeveloperApi :: * Abstract class for evaluators that compute metrics from predictions. */ +@Since("1.5.0") @DeveloperApi abstract class Evaluator extends Params { @@ -35,6 +36,7 @@ abstract class Evaluator extends Params { * @param paramMap parameter map that specifies the input columns and output metrics * @return metric */ + @Since("1.5.0") def evaluate(dataset: DataFrame, paramMap: ParamMap): Double = { this.copy(paramMap).evaluate(dataset) } @@ -44,6 +46,7 @@ abstract class Evaluator extends Params { * @param dataset a dataset that contains labels/observations and predictions. * @return metric */ + @Since("1.5.0") def evaluate(dataset: DataFrame): Double /** @@ -51,7 +54,9 @@ abstract class Evaluator extends Params { * or minimized (false). * A given evaluator may support multiple metrics which may be maximized or minimized. */ + @Since("1.5.0") def isLargerBetter: Boolean = true + @Since("1.5.0") override def copy(extra: ParamMap): Evaluator } diff --git a/mllib/src/main/scala/org/apache/spark/ml/evaluation/MulticlassClassificationEvaluator.scala b/mllib/src/main/scala/org/apache/spark/ml/evaluation/MulticlassClassificationEvaluator.scala index f73d234507..df5f04ca5a 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/evaluation/MulticlassClassificationEvaluator.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/evaluation/MulticlassClassificationEvaluator.scala @@ -17,7 +17,7 @@ package org.apache.spark.ml.evaluation -import org.apache.spark.annotation.Experimental +import org.apache.spark.annotation.{Experimental, Since} import org.apache.spark.ml.param.{ParamMap, ParamValidators, Param} import org.apache.spark.ml.param.shared.{HasLabelCol, HasPredictionCol} import org.apache.spark.ml.util.{SchemaUtils, Identifiable} @@ -29,10 +29,12 @@ import org.apache.spark.sql.types.DoubleType * :: Experimental :: * Evaluator for multiclass classification, which expects two input columns: score and label. */ +@Since("1.5.0") @Experimental -class MulticlassClassificationEvaluator (override val uid: String) +class MulticlassClassificationEvaluator @Since("1.5.0") (@Since("1.5.0") override val uid: String) extends Evaluator with HasPredictionCol with HasLabelCol { + @Since("1.5.0") def this() = this(Identifiable.randomUID("mcEval")) /** @@ -40,6 +42,7 @@ class MulticlassClassificationEvaluator (override val uid: String) * `"weightedPrecision"`, `"weightedRecall"`) * @group param */ + @Since("1.5.0") val metricName: Param[String] = { val allowedParams = ParamValidators.inArray(Array("f1", "precision", "recall", "weightedPrecision", "weightedRecall")) @@ -48,19 +51,24 @@ class MulticlassClassificationEvaluator (override val uid: String) } /** @group getParam */ + @Since("1.5.0") def getMetricName: String = $(metricName) /** @group setParam */ + @Since("1.5.0") def setMetricName(value: String): this.type = set(metricName, value) /** @group setParam */ + @Since("1.5.0") def setPredictionCol(value: String): this.type = set(predictionCol, value) /** @group setParam */ + @Since("1.5.0") def setLabelCol(value: String): this.type = set(labelCol, value) setDefault(metricName -> "f1") + @Since("1.5.0") override def evaluate(dataset: DataFrame): Double = { val schema = dataset.schema SchemaUtils.checkColumnType(schema, $(predictionCol), DoubleType) @@ -81,6 +89,7 @@ class MulticlassClassificationEvaluator (override val uid: String) metric } + @Since("1.5.0") override def isLargerBetter: Boolean = $(metricName) match { case "f1" => true case "precision" => true @@ -89,5 +98,6 @@ class MulticlassClassificationEvaluator (override val uid: String) case "weightedRecall" => true } + @Since("1.5.0") override def copy(extra: ParamMap): MulticlassClassificationEvaluator = defaultCopy(extra) } diff --git a/mllib/src/main/scala/org/apache/spark/ml/evaluation/RegressionEvaluator.scala b/mllib/src/main/scala/org/apache/spark/ml/evaluation/RegressionEvaluator.scala index d21c88ab9b..3fd34d8571 100644 --- a/mllib/src/main/scala/org/apache/spark/ml/evaluation/RegressionEvaluator.scala +++ b/mllib/src/main/scala/org/apache/spark/ml/evaluation/RegressionEvaluator.scala @@ -17,7 +17,7 @@ package org.apache.spark.ml.evaluation -import org.apache.spark.annotation.Experimental +import org.apache.spark.annotation.{Experimental, Since} import org.apache.spark.ml.param.{Param, ParamMap, ParamValidators} import org.apache.spark.ml.param.shared.{HasLabelCol, HasPredictionCol} import org.apache.spark.ml.util.{Identifiable, SchemaUtils} @@ -29,10 +29,12 @@ import org.apache.spark.sql.types.DoubleType * :: Experimental :: * Evaluator for regression, which expects two input columns: prediction and label. */ +@Since("1.4.0") @Experimental -final class RegressionEvaluator(override val uid: String) +final class RegressionEvaluator @Since("1.4.0") (@Since("1.4.0") override val uid: String) extends Evaluator with HasPredictionCol with HasLabelCol { + @Since("1.4.0") def this() = this(Identifiable.randomUID("regEval")) /** @@ -43,25 +45,31 @@ final class RegressionEvaluator(override val uid: String) * we take and output the negative of this metric. * @group param */ + @Since("1.4.0") val metricName: Param[String] = { val allowedParams = ParamValidators.inArray(Array("mse", "rmse", "r2", "mae")) new Param(this, "metricName", "metric name in evaluation (mse|rmse|r2|mae)", allowedParams) } /** @group getParam */ + @Since("1.4.0") def getMetricName: String = $(metricName) /** @group setParam */ + @Since("1.4.0") def setMetricName(value: String): this.type = set(metricName, value) /** @group setParam */ + @Since("1.4.0") def setPredictionCol(value: String): this.type = set(predictionCol, value) /** @group setParam */ + @Since("1.4.0") def setLabelCol(value: String): this.type = set(labelCol, value) setDefault(metricName -> "rmse") + @Since("1.4.0") override def evaluate(dataset: DataFrame): Double = { val schema = dataset.schema SchemaUtils.checkColumnType(schema, $(predictionCol), DoubleType) @@ -81,6 +89,7 @@ final class RegressionEvaluator(override val uid: String) metric } + @Since("1.4.0") override def isLargerBetter: Boolean = $(metricName) match { case "rmse" => false case "mse" => false @@ -88,5 +97,6 @@ final class RegressionEvaluator(override val uid: String) case "mae" => false } + @Since("1.5.0") override def copy(extra: ParamMap): RegressionEvaluator = defaultCopy(extra) } |