Github user Lewuathe commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8884#discussion_r41856633
  
    --- 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)
    +      val instances: RDD[WeightedLeastSquares.Instance] = dataset.select(
    +        col($(labelCol)), w, col($(featuresCol))).map {
    +          case Row(label: Double, weight: Double, features: Vector) =>
    +            WeightedLeastSquares.Instance(weight, features, label)
    +      }
    +
    +      val optimizer = new WeightedLeastSquares($(fitIntercept), 
$(regParam),
    +        $(standardization), true)
    +      val model = optimizer.fit(instances)
    +      // When it is trained by WeightedLeastSquares, training summary does 
not
    +      // attached returned model.
    +      val lrModel = new LinearRegressionModel(uid, model.coefficients, 
model.intercept)
    --- End diff --
    
    The finally returned value is copied at L.177. Is it also necessary to copy 
here?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to