Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/10702#discussion_r51354776
 Diff: mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala 
@@ 219,33 +219,44 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") override
val uid: String
}
val yMean = ySummarizer.mean(0)
 val yStd = math.sqrt(ySummarizer.variance(0))

 // If the yStd is zero, then the intercept is yMean with zero coefficient;
 // as a result, training is not needed.
 if (yStd == 0.0) {
 logWarning(s"The standard deviation of the label is zero, so the coefficients will
be " +
 s"zeros and the intercept will be the mean of the label; as a result, " +
 s"training is not needed.")
 if (handlePersistence) instances.unpersist()
 val coefficients = Vectors.sparse(numFeatures, Seq())
 val intercept = yMean

 val model = new LinearRegressionModel(uid, coefficients, intercept)
 // Handle possible missing or invalid prediction columns
 val (summaryModel, predictionColName) = model.findSummaryModelAndPredictionCol()

 val trainingSummary = new LinearRegressionTrainingSummary(
 summaryModel.transform(dataset),
 predictionColName,
 $(labelCol),
 model,
 Array(0D),
 $(featuresCol),
 Array(0D))
 return copyValues(model.setSummary(trainingSummary))
+ val rawYStd = math.sqrt(ySummarizer.variance(0))
+ if (rawYStd == 0.0) {
+ if ($(fitIntercept)  yMean==0.0) {
+ // If the rawYStd is zero and fitIntercept=true, then the intercept is yMean
with
+ // zero coefficient; as a result, training is not needed.
+ // Also, if yMean==0 and rawYStd==0, all the coefficients are zero regardless
of
+ // the fitIntercept
+ logWarning(s"The standard deviation of the label is zero, so the coefficients
will be " +
 End diff 
Maybe you want to update the warning message for the second situation as well.

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, email: reviewsunsubscribe@spark.apache.org
For additional commands, email: reviewshelp@spark.apache.org
