Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/10788#discussion_r50931598
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/classification/LogisticRegression.scala
---
@@ -343,22 +355,36 @@ class LogisticRegression @Since("1.2.0") (
val initialCoefficientsWithIntercept =
Vectors.zeros(if ($(fitIntercept)) numFeatures + 1 else
numFeatures)
- if ($(fitIntercept)) {
+ if (optInitialModel.isDefined &&
optInitialModel.get.coefficients.size != numFeatures) {
+ val vec = optInitialModel.get.coefficients
+ logWarning(
+ s"Initial coefficients provided ${vec} did not match the
expected size ${numFeatures}")
+ }
+
+ if (optInitialModel.isDefined &&
optInitialModel.get.coefficients.size == numFeatures) {
+ val initialCoefficientsWithInterceptArray =
initialCoefficientsWithIntercept.toArray
+ optInitialModel.get.coefficients.foreachActive { case (index,
value) =>
+ initialCoefficientsWithInterceptArray(index) = value
+ }
+ if ($(fitIntercept)) {
+ initialCoefficientsWithInterceptArray(numFeatures) ==
optInitialModel.get.intercept
+ }
+ } else if ($(fitIntercept)) {
/*
For binary logistic regression, when we initialize the
coefficients as zeros,
it will converge faster if we initialize the intercept such
that
it follows the distribution of the labels.
{{{
- P(0) = 1 / (1 + \exp(b)), and
- P(1) = \exp(b) / (1 + \exp(b))
+ P(0) = 1 / (1 + \exp(b)), and
+ P(1) = \exp(b) / (1 + \exp(b))
}}}, hence
{{{
- b = \log{P(1) / P(0)} = \log{count_1 / count_0}
+ b = \log{P(1) / P(0)} = \log{count_1 / count_0}
}}}
*/
- initialCoefficientsWithIntercept.toArray(numFeatures) = math.log(
- histogram(1) / histogram(0))
+ initialCoefficientsWithIntercept.toArray(numFeatures)
+ = math.log(histogram(1) / histogram(0))
--- End diff --
revert this change.
---
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]