Github user dbtsai commented on a diff in the pull request: https://github.com/apache/spark/pull/8853#discussion_r40767420 --- Diff: mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala --- @@ -541,36 +536,38 @@ private class LeastSquaresAggregator( private val gradientSumArray = Array.ofDim[Double](dim) /** - * Add a new training data to this LeastSquaresAggregator, and update the loss and gradient + * Add a new training instance to this LeastSquaresAggregator, and update the loss and gradient * of the objective function. * - * @param instance The data point instance to be added. + * @param instance The instance of data point to be added. * @return This LeastSquaresAggregator object. */ - def add(instance: Instance): this.type = - instance match { case Instance(label, weight, features) => - require(dim == features.size, s"Dimensions mismatch when adding new sample." + - s" Expecting $dim but got ${features.size}.") - require(weight >= 0.0, s"instance weight, ${weight} has to be >= 0.0") - - if (weight == 0.0) return this - - val diff = dot(features, effectiveCoefficientsVector) - label / labelStd + offset - - if (diff != 0) { - val localGradientSumArray = gradientSumArray - features.foreachActive { (index, value) => - if (featuresStd(index) != 0.0 && value != 0.0) { - localGradientSumArray(index) += weight * diff * value / featuresStd(index) + def add(instance: Instance): this.type = { + instance match { + case Instance(label, weight, features) => + require(dim == features.size, s"Dimensions mismatch when adding new sample." + + s" Expecting $dim but got ${features.size}.") + require(weight >= 0.0, s"instance weight, ${weight} has to be >= 0.0") + + if (weight == 0.0) return this + + val diff = dot(features, effectiveCoefficientsVector) - label / labelStd + offset + + if (diff != 0) { + val localGradientSumArray = gradientSumArray + features.foreachActive { (index, value) => + if (featuresStd(index) != 0.0 && value != 0.0) { + localGradientSumArray(index) += weight * diff * value / featuresStd(index) + } } + lossSum += weight * diff * diff / 2.0 } - lossSum += weight * diff * diff / 2.0 - } - totalCnt += 1 - weightSum += weight - this + totalCnt += 1 --- End diff -- The indentation is correct since we added another block. But I'm going to remove this block for your previous comment.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org