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

    https://github.com/apache/spark/pull/13796#discussion_r74964444
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
 ---
    @@ -952,13 +963,160 @@ private class LogisticAggregator(
         val bcFeaturesStd: Broadcast[Array[Double]],
         private val numFeatures: Int,
         numClasses: Int,
    -    fitIntercept: Boolean) extends Serializable {
    +    fitIntercept: Boolean,
    +    multinomial: Boolean) extends Serializable with Logging {
    +
    +  private val numFeaturesPlusIntercept = if (fitIntercept) numFeatures + 1 
else numFeatures
    +  private val coefficientSize = bcCoefficients.value.size
    +  if (multinomial) {
    +    require(numClasses ==  coefficientSize / numFeaturesPlusIntercept, 
s"The number of " +
    +      s"coefficients should be ${numClasses * numFeaturesPlusIntercept} 
but was $coefficientSize")
    +  } else {
    +    require(coefficientSize == numFeaturesPlusIntercept, s"Expected 
$numFeaturesPlusIntercept " +
    +      s"coefficients but got $coefficientSize")
    +    require(numClasses <= 2, s"Binary logistic aggregator requires 
numClasses in {1, 2}" +
    +      s" but found $numClasses.")
    +  }
     
       private var weightSum = 0.0
       private var lossSum = 0.0
     
    -  private val gradientSumArray =
    -    Array.ofDim[Double](if (fitIntercept) numFeatures + 1 else numFeatures)
    +  private val totalCoefficientLength = {
    +    val cols = if (fitIntercept) numFeatures + 1 else numFeatures
    +    val rows = if (multinomial) numClasses else 1
    +    rows * cols
    +  }
    +
    +  private val gradientSumArray = 
Array.ofDim[Double](totalCoefficientLength)
    +
    +  if (multinomial && numClasses < 2) {
    --- End diff --
    
    I updated the doc with details on this and other things. Let me know if 
that's what you had in mind. Also changed to `<= 2`.


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

Reply via email to