Skip to content

Commit

Permalink
[SPARK-24290][ML] add support for Array input for instrumentation.log…
Browse files Browse the repository at this point in the history
…NamedValue

## What changes were proposed in this pull request?

Extend instrumentation.logNamedValue to support Array input
change the logging for "clusterSizes" to new method

## How was this patch tested?

N/A

Please review http://spark.apache.org/contributing.html before opening a pull request.

Author: Lu WANG <lu.wang@databricks.com>

Closes #21347 from ludatabricks/SPARK-24290.
  • Loading branch information
lu-wang-dl authored and mengxr committed Jun 4, 2018
1 parent 7297ae0 commit b24d3db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Expand Up @@ -276,8 +276,7 @@ class BisectingKMeans @Since("2.0.0") (
val summary = new BisectingKMeansSummary(
model.transform(dataset), $(predictionCol), $(featuresCol), $(k))
model.setSummary(Some(summary))
// TODO: need to extend logNamedValue to support Array
instr.logNamedValue("clusterSizes", summary.clusterSizes.mkString("[", ",", "]"))
instr.logNamedValue("clusterSizes", summary.clusterSizes)
instr.logSuccess(model)
model
}
Expand Down
Expand Up @@ -426,8 +426,7 @@ class GaussianMixture @Since("2.0.0") (
$(predictionCol), $(probabilityCol), $(featuresCol), $(k), logLikelihood)
model.setSummary(Some(summary))
instr.logNamedValue("logLikelihood", logLikelihood)
// TODO: need to extend logNamedValue to support Array
instr.logNamedValue("clusterSizes", summary.clusterSizes.mkString("[", ",", "]"))
instr.logNamedValue("clusterSizes", summary.clusterSizes)
instr.logSuccess(model)
model
}
Expand Down
Expand Up @@ -359,8 +359,7 @@ class KMeans @Since("1.5.0") (
model.transform(dataset), $(predictionCol), $(featuresCol), $(k))

model.setSummary(Some(summary))
// TODO: need to extend logNamedValue to support Array
instr.logNamedValue("clusterSizes", summary.clusterSizes.mkString("[", ",", "]"))
instr.logNamedValue("clusterSizes", summary.clusterSizes)
instr.logSuccess(model)
if (handlePersistence) {
instances.unpersist()
Expand Down
Expand Up @@ -132,6 +132,19 @@ private[spark] class Instrumentation[E <: Estimator[_]] private (
log(compact(render(name -> value)))
}

def logNamedValue(name: String, value: Array[String]): Unit = {
log(compact(render(name -> compact(render(value.toSeq)))))
}

def logNamedValue(name: String, value: Array[Long]): Unit = {
log(compact(render(name -> compact(render(value.toSeq)))))
}

def logNamedValue(name: String, value: Array[Double]): Unit = {
log(compact(render(name -> compact(render(value.toSeq)))))
}


/**
* Logs the successful completion of the training session.
*/
Expand Down

0 comments on commit b24d3db

Please sign in to comment.