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

    https://github.com/apache/spark/pull/8197#discussion_r37345734
  
    --- Diff: docs/ml-linear-methods.md ---
    @@ -118,12 +133,114 @@ lrModel = lr.fit(training)
     print("Weights: " + str(lrModel.weights))
     print("Intercept: " + str(lrModel.intercept))
     {% endhighlight %}
    +</div>
     
     </div>
     
    +The `spark.ml` implementation of logistic regression also supports
    +extracting a summary of the model over the training set. Note that the
    +predictions and metrics which are stored as `Datafram`s in
    +`BinaryLogisticRegressionSummary` are annoted `@transient` and hence
    +only available on the driver.
    +
    +<div class="codetabs">
    +
    +<div data-lang="scala" markdown="1">
    +
    
+[`LogisticRegressionTrainingSummary`](api/scala/index.html#org.apache.spark.ml.classification.LogisticRegressionTrainingSummary)
    +provides a summary for a
    
+[`LogisticRegressionModel`](api/scala/index.html#org.apache.spark.ml.classification.LogisticRegressionModel).
    +Currently, only binary classification is supported and the
    +summary must be explicitly cast to
    
+[`BinaryLogisticRegressionTrainingSummary`](api/scala/index.html#org.apache.spark.ml.classification.BinaryLogisticRegressionTrainingSummary).
    +This will likely change when multiclass classification is supported.
    +
    +Continuing the earlier example:
    +
    +{% highlight scala %}
    +// Extract the summary from the returned LogisticRegressionModel instance 
trained in the earlier example
    +val trainingSummary = lrModel.summary
    +
    +// Obtain the loss per iteration.
    +val objectiveHistory = trainingSummary.objectiveHistory
    +objectiveHistory.foreach(loss => println(loss))
    +
    +// Obtain the metrics useful to judge performance on test data.
    +// We cast the summary to a BinaryLogisticRegressionSummary since the 
problem is a
    +// binary classification problem.
    +val binarySummary = 
trainingSummary.asInstanceOf[BinaryLogisticRegressionSummary]
    +
    +// Obtain the receiver-operating characteristic as a dataframe and 
areaUnderROC.
    +val roc = binarySummary.roc
    +roc.show()
    +roc.select("FPR").show()
    +println(binarySummary.areaUnderROC)
    +
    +// Get the threshold corresponding to the maximum F-Measure and rerun 
LogisticRegression with
    +// this selected threshold.
    +val fMeasure = binarySummary.fMeasureByThreshold
    +val maxFMeasure = fMeasure.select(max("F-Measure")).head().getDouble(0)
    +val bestThreshold = fMeasure.where($"F-Measure" === maxFMeasure).
    +  select("threshold").head().getDouble(0)
    +logReg.setThreshold(bestThreshold)
    +logReg.fit(logRegDataFrame)
    +{% endhighlight %}
     </div>
     
    -### Optimization
    +<div data-lang="java" markdown="1">
    
+[`LogisticRegressionTrainingSummary`](api/java/org/apache/spark/ml/classification/LogisticRegressionTrainingSummary.html)
    +provides a summary for a
    
+[`LogisticRegressionModel`](api/java/org/apache/spark/ml/classification/LogisticRegressionModel.html).
    +Currently, only binary classification is supported and the
    +summary must be explicitly cast to
    
+[`BinaryLogisticRegressionTrainingSummary`](api/java/org/apache/spark/ml/classification/BinaryLogisticRegressionTrainingSummary.html).
    +This will likely change when multiclass classification is supported.
    +
    +Continuing the earlier example:
    +
    +{% highlight java %}
    +// Extract the summary from the returned LogisticRegressionModel instance 
trained in the earlier example
    +LogisticRegressionTrainingSummary trainingSummary = logRegModel.summary();
    +
    +// Obtain the loss per iteration.
    +double[] objectiveHistory = trainingSummary.objectiveHistory();
    +for (double lossPerIteration : objectiveHistory) {
    --- End diff --
    
    Nope, see [Google's Java Style 
Guide](https://google.github.io/styleguide/javaguide.html#s4.6.2-horizontal-whitespace)


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