zhengruifeng commented on a change in pull request #31693:
URL: https://github.com/apache/spark/pull/31693#discussion_r584575049
##########
File path:
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
##########
@@ -934,31 +934,56 @@ class LogisticRegression @Since("1.2.0") (
instances: RDD[Instance],
actualBlockSizeInMB: Double,
featuresStd: Array[Double],
+ featuresMean: Array[Double],
numClasses: Int,
- initialCoefWithInterceptMatrix: Matrix,
+ initialCoefWithInterceptArray: Array[Double],
regularization: Option[L2Regularization],
optimizer: FirstOrderMinimizer[BDV[Double], DiffFunction[BDV[Double]]])
= {
val numFeatures = featuresStd.length
val bcFeaturesStd = instances.context.broadcast(featuresStd)
+ val bcFeaturesMean = instances.context.broadcast(featuresMean)
- val standardized = instances.mapPartitions { iter =>
+ val scaled = instances.mapPartitions { iter =>
val inverseStd = bcFeaturesStd.value.map { std => if (std != 0) 1.0 /
std else 0.0 }
val func = StandardScalerModel.getTransformFunc(Array.empty, inverseStd,
false, true)
iter.map { case Instance(label, weight, vec) => Instance(label, weight,
func(vec)) }
}
val maxMemUsage = (actualBlockSizeInMB * 1024L * 1024L).ceil.toLong
- val blocks = InstanceBlock.blokifyWithMaxMemUsage(standardized,
maxMemUsage)
+ val blocks = InstanceBlock.blokifyWithMaxMemUsage(scaled, maxMemUsage)
.persist(StorageLevel.MEMORY_AND_DISK)
.setName(s"training blocks (blockSizeInMB=$actualBlockSizeInMB)")
- val getAggregatorFunc = new BlockLogisticAggregator(numFeatures,
numClasses, $(fitIntercept),
- checkMultinomial(numClasses))(_)
+ val multinomial = checkMultinomial(numClasses)
+ val fitWithMean = !multinomial && $(fitIntercept) &&
Review comment:
for binary lor, we can center the input vector, if and only if:
1, fitIntercept is true;
2, no penalization on the intercept, it seem this is always true in existing
impl;
3, no bounds on the intercept
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]