Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/14834#discussion_r78101327
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
---
@@ -311,8 +348,25 @@ class LogisticRegression @Since("1.2.0") (
val histogram = labelSummarizer.histogram
val numInvalid = labelSummarizer.countInvalid
- val numClasses = histogram.length
val numFeatures = summarizer.mean.size
+ val numFeaturesPlusIntercept = if (getFitIntercept) numFeatures + 1
else numFeatures
+
+ val numClasses =
MetadataUtils.getNumClasses(dataset.schema($(labelCol))) match {
+ case Some(n: Int) =>
+ require(n >= histogram.length, s"Specified number of classes $n
was " +
+ s"less than the number of unique labels ${histogram.length}.")
+ n
+ case None => histogram.length
+ }
+ val isBinaryClassification = numClasses == 1 || numClasses == 2
+ val isMultinomial = ($(family) == "auto" && !isBinaryClassification) ||
+ ($(family) == "multinomial")
+ val numCoefficientSets = if (isMultinomial) numClasses else 1
+
--- End diff --
maybe it's easier to read
```scala
val (isBinomial, isMultinomial) = {
$(family) match {
case "binomial" =>
require(numClasses == 1 || numClasses == 2, s"Binomial family only
supports 1 or 2 " +
+ s"outcome classes but found $numClasses.")
(true, false)
case "multinomial" =>
(false, true)
case "auto": => ....
case _: throw new IllegalArgExpcetion("Unsupported family")
}
}
```
---
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]