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

    https://github.com/apache/spark/pull/10207#discussion_r47006668
  
    --- Diff: docs/ml-classification-regression.md ---
    @@ -0,0 +1,733 @@
    +---
    +layout: global
    +title: Classification and regression - spark.ml
    +displayTitle: Classification and regression in spark.ml
    +---
    +
    +
    +`\[
    +\newcommand{\R}{\mathbb{R}}
    +\newcommand{\E}{\mathbb{E}}
    +\newcommand{\x}{\mathbf{x}}
    +\newcommand{\y}{\mathbf{y}}
    +\newcommand{\wv}{\mathbf{w}}
    +\newcommand{\av}{\mathbf{\alpha}}
    +\newcommand{\bv}{\mathbf{b}}
    +\newcommand{\N}{\mathbb{N}}
    +\newcommand{\id}{\mathbf{I}}
    +\newcommand{\ind}{\mathbf{1}}
    +\newcommand{\0}{\mathbf{0}}
    +\newcommand{\unit}{\mathbf{e}}
    +\newcommand{\one}{\mathbf{1}}
    +\newcommand{\zero}{\mathbf{0}}
    +\]`
    +
    +**Table of Contents**
    +
    +* This will become a table of contents (this text will be scraped).
    +{:toc}
    +
    +In MLlib, we implement popular linear methods such as logistic
    +regression and linear least squares with $L_1$ or $L_2$ regularization.
    +Refer to [the linear methods in mllib](mllib-linear-methods.html) for
    +details.  In `spark.ml`, we also include Pipelines API for [Elastic
    +net](http://en.wikipedia.org/wiki/Elastic_net_regularization), a hybrid
    +of $L_1$ and $L_2$ regularization proposed in [Zou et al, Regularization
    +and variable selection via the elastic
    +net](http://users.stat.umn.edu/~zouxx019/Papers/elasticnet.pdf).
    +Mathematically, it is defined as a convex combination of the $L_1$ and
    +the $L_2$ regularization terms:
    +`\[
    +\alpha \left( \lambda \|\wv\|_1 \right) + (1-\alpha) \left( 
\frac{\lambda}{2}\|\wv\|_2^2 \right) , \alpha \in [0, 1], \lambda \geq 0
    +\]`
    +By setting $\alpha$ properly, elastic net contains both $L_1$ and $L_2$
    +regularization as special cases. For example, if a [linear
    +regression](https://en.wikipedia.org/wiki/Linear_regression) model is
    +trained with the elastic net parameter $\alpha$ set to $1$, it is
    +equivalent to a
    +[Lasso](http://en.wikipedia.org/wiki/Least_squares#Lasso_method) model.
    +On the other hand, if $\alpha$ is set to $0$, the trained model reduces
    +to a [ridge
    +regression](http://en.wikipedia.org/wiki/Tikhonov_regularization) model.
    +We implement Pipelines API for both linear regression and logistic
    +regression with elastic net regularization.
    +
    +# Regression
    +
    +## Linear regression
    +
    +The interface for working with linear regression models and model
    +summaries is similar to the logistic regression case. The following
    +example demonstrates training an elastic net regularized linear
    +regression model and extracting model summary statistics.
    +
    +<div class="codetabs">
    +
    +<div data-lang="scala" markdown="1">
    +{% include_example 
scala/org/apache/spark/examples/ml/LinearRegressionWithElasticNetExample.scala 
%}
    +</div>
    +
    +<div data-lang="java" markdown="1">
    +{% include_example 
java/org/apache/spark/examples/ml/JavaLinearRegressionWithElasticNetExample.java
 %}
    +</div>
    +
    +<div data-lang="python" markdown="1">
    +<!--- TODO: Add python model summaries once implemented -->
    +{% include_example python/ml/linear_regression_with_elastic_net.py %}
    +</div>
    +
    +</div>
    +
    +## Survival regression
    +
    +
    +In `spark.ml`, we implement the [Accelerated failure time 
(AFT)](https://en.wikipedia.org/wiki/Accelerated_failure_time_model) 
    +model which is a parametric survival regression model for censored data. 
    +It describes a model for the log of survival time, so it's often called 
    +log-linear model for survival analysis. Different from 
    +[Proportional 
hazards](https://en.wikipedia.org/wiki/Proportional_hazards_model) model
    +designed for the same purpose, the AFT model is more easily to parallelize 
    +because each instance contribute to the objective function independently.
    +
    +Given the values of the covariates $x^{'}$, for random lifetime $t_{i}$ of 
    +subjects i = 1, ..., n, with possible right-censoring, 
    +the likelihood function under the AFT model is given as:
    +`\[
    
+L(\beta,\sigma)=\prod_{i=1}^n[\frac{1}{\sigma}f_{0}(\frac{\log{t_{i}}-x^{'}\beta}{\sigma})]^{\delta_{i}}S_{0}(\frac{\log{t_{i}}-x^{'}\beta}{\sigma})^{1-\delta_{i}}
    +\]`
    +Where $\delta_{i}$ is the indicator of the event has occurred i.e. 
uncensored or not.
    +Using $\epsilon_{i}=\frac{\log{t_{i}}-x^{'}\beta}{\sigma}$, the 
log-likelihood function
    +assumes the form:
    +`\[
    
+\iota(\beta,\sigma)=\sum_{i=1}^{n}[-\delta_{i}\log\sigma+\delta_{i}\log{f_{0}}(\epsilon_{i})+(1-\delta_{i})\log{S_{0}(\epsilon_{i})}]
    +\]`
    +Where $S_{0}(\epsilon_{i})$ is the baseline survivor function,
    +and $f_{0}(\epsilon_{i})$ is corresponding density function.
    +
    +The most commonly used AFT model is based on the Weibull distribution of 
the survival time. 
    +The Weibull distribution for lifetime corresponding to extreme value 
distribution for 
    +log of the lifetime, and the $S_{0}(\epsilon)$ function is:
    +`\[   
    +S_{0}(\epsilon_{i})=\exp(-e^{\epsilon_{i}})
    +\]`
    +the $f_{0}(\epsilon_{i})$ function is:
    +`\[
    +f_{0}(\epsilon_{i})=e^{\epsilon_{i}}\exp(-e^{\epsilon_{i}})
    +\]`
    +The log-likelihood function for AFT model with Weibull distribution of 
lifetime is:
    +`\[
    +\iota(\beta,\sigma)= 
-\sum_{i=1}^n[\delta_{i}\log\sigma-\delta_{i}\epsilon_{i}+e^{\epsilon_{i}}]
    +\]`
    +Due to minimizing the negative log-likelihood equivalent to maximum a 
posteriori probability,
    +the loss function we use to optimize is $-\iota(\beta,\sigma)$.
    +The gradient functions for $\beta$ and $\log\sigma$ respectively are:
    +`\[   
    +\frac{\partial (-\iota)}{\partial 
\beta}=\sum_{1=1}^{n}[\delta_{i}-e^{\epsilon_{i}}]\frac{x_{i}}{\sigma}
    +\]`
    +`\[ 
    +\frac{\partial (-\iota)}{\partial 
(\log\sigma)}=\sum_{i=1}^{n}[\delta_{i}+(\delta_{i}-e^{\epsilon_{i}})\epsilon_{i}]
    +\]`
    +
    +The AFT model can be formulated as a convex optimization problem, 
    +i.e. the task of finding a minimizer of a convex function 
$-\iota(\beta,\sigma)$ 
    +that depends coefficients vector $\beta$ and the log of scale parameter 
$\log\sigma$.
    +The optimization algorithm underlying the implementation is L-BFGS.
    +The implementation matches the result from R's survival function 
    
+[survreg](https://stat.ethz.ch/R-manual/R-devel/library/survival/html/survreg.html)
    +
    +## Example:
    +
    +<div class="codetabs">
    +
    +<div data-lang="scala" markdown="1">
    +{% include_example 
scala/org/apache/spark/examples/ml/AFTSurvivalRegressionExample.scala %}
    +</div>
    +
    +<div data-lang="java" markdown="1">
    +{% include_example 
java/org/apache/spark/examples/ml/JavaAFTSurvivalRegressionExample.java %}
    +</div>
    +
    +<div data-lang="python" markdown="1">
    +{% include_example python/ml/aft_survival_regression.py %}
    +</div>
    +
    +</div>
    +
    +
    +# Classification
    +
    +## Logistic regression
    +
    +The following example shows how to train a logistic regression model
    +with elastic net regularization. `elasticNetParam` corresponds to
    +$\alpha$ and `regParam` corresponds to $\lambda$.
    +
    +<div class="codetabs">
    +
    +<div data-lang="scala" markdown="1">
    +{% include_example 
scala/org/apache/spark/examples/ml/LogisticRegressionWithElasticNetExample.scala
 %}
    +</div>
    +
    +<div data-lang="java" markdown="1">
    +{% include_example 
java/org/apache/spark/examples/ml/JavaLogisticRegressionWithElasticNetExample.java
 %}
    +</div>
    +
    +<div data-lang="python" markdown="1">
    +{% include_example python/ml/logistic_regression_with_elastic_net.py %}
    +</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 `Dataframe` in
    +`BinaryLogisticRegressionSummary` are annotated `@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)
    --- End diff --
    
    I'd start with a link to the LogisticRegression docs.  Then you can list 
these less important links.


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

Reply via email to