Skip to content

Commit

Permalink
[SPARK-13132][MLLIB] cache standardization param value in LogisticReg…
Browse files Browse the repository at this point in the history
…ression

cache the value of the standardization Param in LogisticRegression, rather than re-fetching it from the ParamMap for every index and every optimization step in the quasi-newton optimizer

also, fix Param#toString to cache the stringified representation, rather than re-interpolating it on every call, so any other implementations that have similar repeated access patterns will see a benefit.

this change improves training times for one of my test sets from ~7m30s to ~4m30s

Author: Gary King <gary@idibon.com>

Closes #11027 from idigary/spark-13132-optimize-logistic-regression.
  • Loading branch information
idigary authored and srowen committed Feb 7, 2016
1 parent 81da3be commit bc8890b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ class LogisticRegression @Since("1.2.0") (
val optimizer = if ($(elasticNetParam) == 0.0 || $(regParam) == 0.0) {
new BreezeLBFGS[BDV[Double]]($(maxIter), 10, $(tol))
} else {
val standardizationParam = $(standardization)
def regParamL1Fun = (index: Int) => {
// Remove the L1 penalization on the intercept
if (index == numFeatures) {
0.0
} else {
if ($(standardization)) {
if (standardizationParam) {
regParamL1
} else {
// If `standardization` is false, we still standardize the data
Expand Down
4 changes: 3 additions & 1 deletion mllib/src/main/scala/org/apache/spark/ml/param/params.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class Param[T](val parent: String, val name: String, val doc: String, val isVali
}
}

override final def toString: String = s"${parent}__$name"
private[this] val stringRepresentation = s"${parent}__$name"

override final def toString: String = stringRepresentation

override final def hashCode: Int = toString.##

Expand Down

0 comments on commit bc8890b

Please sign in to comment.