Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/14834#discussion_r78109655
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
---
@@ -333,22 +387,18 @@ class LogisticRegression @Since("1.2.0") (
val isConstantLabel = histogram.count(_ != 0) == 1
- if (numClasses > 2) {
- val msg = s"LogisticRegression with ElasticNet in ML package only
supports " +
- s"binary classification. Found $numClasses in the input dataset.
Consider using " +
- s"MultinomialLogisticRegression instead."
- logError(msg)
- throw new SparkException(msg)
- } else if ($(fitIntercept) && numClasses == 2 && isConstantLabel) {
- logWarning(s"All labels are one and fitIntercept=true, so the
coefficients will be " +
- s"zeros and the intercept will be positive infinity; as a
result, " +
- s"training is not needed.")
- (Vectors.sparse(numFeatures, Seq()), Double.PositiveInfinity,
Array.empty[Double])
- } else if ($(fitIntercept) && numClasses == 1) {
- logWarning(s"All labels are zero and fitIntercept=true, so the
coefficients will be " +
- s"zeros and the intercept will be negative infinity; as a
result, " +
- s"training is not needed.")
- (Vectors.sparse(numFeatures, Seq()), Double.NegativeInfinity,
Array.empty[Double])
+ if ($(fitIntercept) && isConstantLabel) {
+ logWarning(s"All labels are the same value and fitIntercept=true,
so the coefficients " +
+ s"will be zeros. Training is not needed.")
+ val constantLabelIndex = Vectors.dense(histogram).argmax
+ val coefficientMatrix = Matrices.sparse(numCoefficientSets,
numFeatures,
+ Array.fill(numFeatures + 1)(0), Array.empty[Int],
Array.empty[Double])
--- End diff --
I think we should be able to tune the sparse matrix implementation later
since it's not efficiency to store `Array.fill(numFeatures + 1)(0)` for high
dimensional problems. For now, you check `if (numClasses > numFeatures+1)`, you
store it as CSC, otherwise, CSR will be prefer and this is most majority of use
case.
---
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]