Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-24290][ML] add support for Array input for instrumentation.logNamedValue #21347

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,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 -> value.toSeq)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from what we had for clustering.

instr.logNamedValue("clusterSizes", summary.clusterSizes.mkString("[", ",", "]"))
.

In that implementation, we logged the entire array as a JSON string, which is equivalent to

compact(render(name -> compact(render(value.toSeq)))))

instead of JSONify the raw data structure. It really depends on how users load the data. Do they treat named value as a map or as sub-fields. If it is the former, we should have consistent value types and then we also need to update logNamedValue(String, Long). @jkbradley What is your preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so you're pointing out that our current approach is inconsistent: JSONifying array values (for clustering) but not JSONifying scalar values (Long, etc.)? I don't have a good sense of what's best, but if we just have to pick something, I'd suggest not JSONifying values since doing so creates slightly longer strings to log (with extra quotes) and since that maintains a stable format from Spark 2.3.

}

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

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


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