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

    https://github.com/apache/spark/pull/10788#discussion_r50370414
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/classification/LogisticRegression.scala
 ---
    @@ -374,4 +384,82 @@ class LogisticRegressionWithLBFGS
           new LogisticRegressionModel(weights, intercept, numFeatures, 
numOfLinearPredictor + 1)
         }
       }
    +
    +  /**
    +   * Run Logistic Regression with the configured parameters on an input RDD
    +   * of LabeledPoint entries.
    +   *
    +   * If a known updater is used calls the ml implementation, to avoid
    +   * applying a regularization penalty to the intercept, otherwise
    +   * defaults to the mllib implementation. If more than two classes
    +   * or feature scaling is disabled, always uses mllib implementation.
    +   * If using ml implementation, uses ml code to generate initial weights.
    +   */
    +  override def run(input: RDD[LabeledPoint]): LogisticRegressionModel = {
    +    run(input, generateInitialWeights(input), userSuppliedWeights = false)
    +  }
    +
    +  /**
    +   * Run Logistic Regression with the configured parameters on an input RDD
    +   * of LabeledPoint entries starting from the initial weights provided.
    +   *
    +   * If a known updater is used calls the ml implementation, to avoid
    +   * applying a regularization penalty to the intercept, otherwise
    +   * defaults to the mllib implementation. If more than two classes
    +   * or feature scaling is disabled, always uses mllib implementation.
    +   * Uses user provided weights.
    +   */
    +  override def run(input: RDD[LabeledPoint], initialWeights: Vector): 
LogisticRegressionModel = {
    +    run(input, initialWeights, userSuppliedWeights = true)
    +  }
    +
    +  private def run(input: RDD[LabeledPoint], initialWeights: Vector, 
userSuppliedWeights: Boolean):
    +      LogisticRegressionModel = {
    +    // ml's Logisitic regression only supports binary classifcation 
currently.
    +    if (numOfLinearPredictor == 1) {
    +      def runWithMlLogisitcRegression(elasticNetParam: Double) = {
    +        // Prepare the ml LogisticRegression based on our settings
    +        val lr = new 
org.apache.spark.ml.classification.LogisticRegression()
    +        lr.setRegParam(optimizer.getRegParam())
    +        lr.setElasticNetParam(elasticNetParam)
    +        lr.setStandardization(useFeatureScaling)
    +        if (userSuppliedWeights) {
    +          val uid = Identifiable.randomUID("logreg-static")
    +          lr.setInitialModel(new 
org.apache.spark.ml.classification.LogisticRegressionModel(
    +            uid, initialWeights, 1.0))
    +        }
    +        lr.setFitIntercept(addIntercept)
    +        lr.setMaxIter(optimizer.getNumIterations())
    +        lr.setTol(optimizer.getConvergenceTol())
    +        // Convert our input into a DataFrame
    +        val sqlContext = new SQLContext(input.context)
    +        import sqlContext.implicits._
    +        val df = input.toDF()
    +        // Determine if we should cache the DF
    +        val handlePersistence = input.getStorageLevel == StorageLevel.NONE
    +        if (handlePersistence) {
    +          df.persist(StorageLevel.MEMORY_AND_DISK)
    +        }
    +        // Train our model
    +        val mlLogisticRegresionModel = lr.train(df)
    +        // unpersist if we persisted
    +        if (handlePersistence) {
    +          df.unpersist()
    +        }
    +        // convert the model
    +        val weights = mlLogisticRegresionModel.weights match {
    +          case x: DenseVector => x
    +          case y: Vector => Vectors.dense(y.toArray)
    +        }
    +        createModel(weights, mlLogisticRegresionModel.intercept)
    +      }
    +      optimizer.getUpdater() match {
    --- End diff --
    
    when `optimizer.getRegParam() == 0.0`, run the old version.


---
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