spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbtsai <...@git.apache.org>
Subject [GitHub] spark pull request #13796: [SPARK-7159][ML] Add multiclass logistic regressi...
Date Wed, 17 Aug 2016 22:32:28 GMT
Github user dbtsai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13796#discussion_r75219906
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
---
    @@ -982,45 +1275,13 @@ private class LogisticAggregator(
                 "coefficients only supports dense vector" +
                   s"but got type ${bcCoefficients.value.getClass}.")
           }
    -      val localGradientSumArray = gradientSumArray
    -
    -      val featuresStd = bcFeaturesStd.value
    -      numClasses match {
    -        case 2 =>
    -          // For Binary Logistic Regression.
    -          val margin = - {
    -            var sum = 0.0
    -            features.foreachActive { (index, value) =>
    -              if (featuresStd(index) != 0.0 && value != 0.0) {
    -                sum += coefficientsArray(index) * (value / featuresStd(index))
    -              }
    -            }
    -            sum + {
    -              if (fitIntercept) coefficientsArray(numFeatures) else 0.0
    -            }
    -          }
    -
    -          val multiplier = weight * (1.0 / (1.0 + math.exp(margin)) - label)
    -
    -          features.foreachActive { (index, value) =>
    -            if (featuresStd(index) != 0.0 && value != 0.0) {
    -              localGradientSumArray(index) += multiplier * (value / featuresStd(index))
    -            }
    -          }
    -
    -          if (fitIntercept) {
    -            localGradientSumArray(numFeatures) += multiplier
    -          }
     
    -          if (label > 0) {
    -            // The following is equivalent to log(1 + exp(margin)) but more numerically
stable.
    -            lossSum += weight * MLUtils.log1pExp(margin)
    -          } else {
    -            lossSum += weight * (MLUtils.log1pExp(margin) - margin)
    -          }
    -        case _ =>
    -          new NotImplementedError("LogisticRegression with ElasticNet in ML package "
+
    -            "only supports binary classification for now.")
    +      if (multinomial) {
    +        multinomialUpdateInPlace(features, weight, label, coefficientsArray, gradientSumArray,
    +          bcFeaturesStd.value, numFeaturesPlusIntercept)
    --- End diff --
    
    For consistency, I'll suggest that you either return `loss` explicitly from `multinomialUpdateInPlace`
and `binaryUpdateInPlace` functions and sum them into `lossSum` to those two private functions
don't use any variable in the class or you remove `coefficientsArray`, `gradientSumArray`,
`bcFeaturesStd.value`, and `numFeaturesPlusIntercept` from the functions.


---
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


Mime
View raw message