You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by yanboliang <gi...@git.apache.org> on 2015/04/01 07:34:57 UTC

[GitHub] spark pull request: [SPARK-6580] [MLLIB] Optimize LogisticRegressi...

Github user yanboliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5249#discussion_r27545988
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/classification/LogisticRegression.scala ---
    @@ -145,13 +135,20 @@ class LogisticRegressionModel (
            */
           var bestClass = 0
           var maxMargin = 0.0
    -      var i = 0
    -      while(i < margins.size) {
    -        if (margins(i) > maxMargin) {
    -          maxMargin = margins(i)
    +      val withBias = if (dataMatrix.size + 1 == dataWithBiasSize) true else false
    +      (0 until numClasses - 1).map { i =>
    +        var margin = 0.0
    +        dataMatrix.foreachActive { (index, value) =>
    +          if (value != 0.0) margin += value * weightsArray((i * dataWithBiasSize) + index)
    --- End diff --
    
    @srowen  Thank you for your comments. I'm not sure that it will make a measurable difference, what I made for this PR is just want to clean code and reduce redundant. This optimization is inspired by #5137 which implements the prediction for Python API and it concerned mainly on code clean rather than performance issue.
    I agree the real optimization may be not computing the weights array every time  prediction is made,  but just like you said it seems like small improvements. I think we should resolve it when we encounter some performance issues and file another ticket.
     


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org