aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwm624@hotmail.com <wm624@hotmail.com>2016-04-29 16:18:25 +0200
committerNick Pentreath <nickp@za.ibm.com>2016-04-29 16:18:25 +0200
commitb6fa7e5934ca5d1c3c757629833396b810894067 (patch)
tree9dd550f4367f3453fc06a2215913bb12251d8700
parent6d5aeaae264579673bb75d32a8e4cd96aad9cf83 (diff)
downloadspark-b6fa7e5934ca5d1c3c757629833396b810894067.tar.gz
spark-b6fa7e5934ca5d1c3c757629833396b810894067.tar.bz2
spark-b6fa7e5934ca5d1c3c757629833396b810894067.zip
[SPARK-14571][ML] Log instrumentation in ALS
## What changes were proposed in this pull request? Add log instrumentation for parameters: rank, numUserBlocks, numItemBlocks, implicitPrefs, alpha, userCol, itemCol, ratingCol, predictionCol, maxIter, regParam, nonnegative, checkpointInterval, seed Add log instrumentation for numUserFeatures and numItemFeatures ## How was this patch tested? Manual test: Set breakpoint in intellij and run def testALS(). Single step debugging and check the log method is called. Author: wm624@hotmail.com <wm624@hotmail.com> Closes #12560 from wangmiao1981/log.
-rw-r--r--mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala5
-rw-r--r--mllib/src/main/scala/org/apache/spark/ml/util/Instrumentation.scala7
2 files changed, 12 insertions, 0 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala b/mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
index 6e4e6a6d85..cbcbfe8249 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/recommendation/ALS.scala
@@ -395,6 +395,10 @@ class ALS(@Since("1.4.0") override val uid: String) extends Estimator[ALSModel]
.map { row =>
Rating(row.getInt(0), row.getInt(1), row.getFloat(2))
}
+ val instrLog = Instrumentation.create(this, ratings)
+ instrLog.logParams(rank, numUserBlocks, numItemBlocks, implicitPrefs, alpha,
+ userCol, itemCol, ratingCol, predictionCol, maxIter,
+ regParam, nonnegative, checkpointInterval, seed)
val (userFactors, itemFactors) = ALS.train(ratings, rank = $(rank),
numUserBlocks = $(numUserBlocks), numItemBlocks = $(numItemBlocks),
maxIter = $(maxIter), regParam = $(regParam), implicitPrefs = $(implicitPrefs),
@@ -403,6 +407,7 @@ class ALS(@Since("1.4.0") override val uid: String) extends Estimator[ALSModel]
val userDF = userFactors.toDF("id", "features")
val itemDF = itemFactors.toDF("id", "features")
val model = new ALSModel(uid, $(rank), userDF, itemDF).setParent(this)
+ instrLog.logSuccess(model)
copyValues(model)
}
diff --git a/mllib/src/main/scala/org/apache/spark/ml/util/Instrumentation.scala b/mllib/src/main/scala/org/apache/spark/ml/util/Instrumentation.scala
index 869104e090..71a626647a 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/util/Instrumentation.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/util/Instrumentation.scala
@@ -85,6 +85,13 @@ private[spark] class Instrumentation[E <: Estimator[_]] private (
}
/**
+ * Logs the value with customized name field.
+ */
+ def logNamedValue(name: String, num: Long): Unit = {
+ log(compact(render(name -> num)))
+ }
+
+ /**
* Logs the successful completion of the training session and the value of the learned model.
*/
def logSuccess(model: Model[_]): Unit = {