Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/8884#discussion_r41809032
--- Diff:
mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala ---
@@ -130,9 +131,54 @@ class LinearRegression(override val uid: String)
def setWeightCol(value: String): this.type = set(weightCol, value)
setDefault(weightCol -> "")
+ /**
+ * Set the solver algorithm used for optimization.
+ * In case of linear regression, this can be "l-bfgs", "normal" and
"auto".
+ * The default value is "auto" which means that the solver algorithm is
+ * selected automatically.
+ * @group setParam
+ */
+ def setSolver(value: String): this.type = set(solver, value)
+ setDefault(solver -> "auto")
+
override protected def train(dataset: DataFrame): LinearRegressionModel
= {
+ // Extract the number of features before deciding optimization solver.
+ val numFeatures = dataset.select(col($(featuresCol))).limit(1).map {
+ case Row(features: Vector) =>
+ features.size
+ }.toArray()(0)
// Extract columns from data. If dataset is persisted, do not persist
instances.
val w = if ($(weightCol).isEmpty) lit(1.0) else col($(weightCol))
+
+ if ($(solver) == "normal" || ($(solver) == "auto"
+ && $(elasticNetParam) == 0.0 && numFeatures <= 4096)) {
+ require($(elasticNetParam) == 0.0, "Only L2 regularization can be
used when normal " +
+ "solver is selected.'")
+ // In case of feature size is small, WeightedLeastSquares can train
more efficiently
+ // because it requires one pass through to the data. (SPARK-10668)
--- End diff --
For low dimensional data, WeightedLeastSquares is more efficiently since
the training algorithm only requires one pass through the data.
---
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]