Github user srowen commented on a diff in the pull request:
https://github.com/apache/spark/pull/5249#discussion_r27511293
--- 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 --
OK, yes you're avoiding computing and saving margins, then looping over
them again. I thought the real optimization was not computing the weights array
every time a prediction is made. I suppose it means potentially storing the
weights twice, but there generally won't be millions of them or anything.
These seem like smallish improvements though, does it make a measurable
difference? I would think that if things like this matter, then it might be
valuable to go further and even avoid `(0 until numClasses - 1)` in favor of a
`while` loop. I'm not suggesting this must be done, but just making sure the
win is happening for the reasons we think it is, and that it's worth some
optimization but not more.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]