You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by me...@apache.org on 2016/01/25 20:52:30 UTC

spark git commit: [SPARK-11965][ML][DOC] Update user guide for RFormula feature interactions

Repository: spark
Updated Branches:
  refs/heads/master 4ee8191e5 -> dd2325d9a


[SPARK-11965][ML][DOC] Update user guide for RFormula feature interactions

Update user guide for RFormula feature interactions. Meanwhile we also update other new features such as supporting string label in Spark 1.6.

Author: Yanbo Liang <yb...@gmail.com>

Closes #10222 from yanboliang/spark-11965.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/dd2325d9
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/dd2325d9
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/dd2325d9

Branch: refs/heads/master
Commit: dd2325d9a7de7bef9a6bc2f0d5f26e605545b52d
Parents: 4ee8191
Author: Yanbo Liang <yb...@gmail.com>
Authored: Mon Jan 25 11:52:26 2016 -0800
Committer: Xiangrui Meng <me...@databricks.com>
Committed: Mon Jan 25 11:52:26 2016 -0800

----------------------------------------------------------------------
 docs/ml-features.md                             | 20 ++++++++++++++++++-
 .../org/apache/spark/ml/feature/RFormula.scala  | 21 ++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/dd2325d9/docs/ml-features.md
----------------------------------------------------------------------
diff --git a/docs/ml-features.md b/docs/ml-features.md
index 677e4bf..5809f65 100644
--- a/docs/ml-features.md
+++ b/docs/ml-features.md
@@ -1121,7 +1121,25 @@ for more details on the API.
 
 ## RFormula
 
-`RFormula` selects columns specified by an [R model formula](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html). It produces a vector column of features and a double column of labels. Like when formulas are used in R for linear regression, string input columns will be one-hot encoded, and numeric columns will be cast to doubles. If not already present in the DataFrame, the output label column will be created from the specified response variable in the formula.
+`RFormula` selects columns specified by an [R model formula](https://stat.ethz.ch/R-manual/R-devel/library/stats/html/formula.html). 
+Currently we support a limited subset of the R operators, including '~', '.', ':', '+', and '-'.
+The basic operators are:
+
+* `~` separate target and terms
+* `+` concat terms, "+ 0" means removing intercept
+* `-` remove a term, "- 1" means removing intercept
+* `:` interaction (multiplication for numeric values, or binarized categorical values)
+* `.` all columns except target
+
+Suppose `a` and `b` are double columns, we use the following simple examples to illustrate the effect of `RFormula`:
+
+* `y ~ a + b` means model `y ~ w0 + w1 * a + w2 * b` where `w0` is the intercept and `w1, w2` are coefficients.
+* `y ~ a + b + a:b - 1` means model `y ~ w1 * a + w2 * b + w3 * a * b` where `w1, w2, w3` are coefficients.
+
+`RFormula` produces a vector column of features and a double or string column of label. 
+Like when formulas are used in R for linear regression, string input columns will be one-hot encoded, and numeric columns will be cast to doubles.
+If the label column is of type string, it will be first transformed to double with `StringIndexer`.
+If the label column does not exist in the DataFrame, the output label column will be created from the specified response variable in the formula.
 
 **Examples**
 

http://git-wip-us.apache.org/repos/asf/spark/blob/dd2325d9/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
----------------------------------------------------------------------
diff --git a/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala b/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
index 6cc9d02..c21da21 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
@@ -45,6 +45,27 @@ private[feature] trait RFormulaBase extends HasFeaturesCol with HasLabelCol {
  * Implements the transforms required for fitting a dataset against an R model formula. Currently
  * we support a limited subset of the R operators, including '~', '.', ':', '+', and '-'. Also see
  * the R formula docs here: http://stat.ethz.ch/R-manual/R-patched/library/stats/html/formula.html
+ *
+ * The basic operators are:
+ *  - `~` separate target and terms
+ *  - `+` concat terms, "+ 0" means removing intercept
+ *  - `-` remove a term, "- 1" means removing intercept
+ *  - `:` interaction (multiplication for numeric values, or binarized categorical values)
+ *  - `.` all columns except target
+ *
+ * Suppose `a` and `b` are double columns, we use the following simple examples
+ * to illustrate the effect of `RFormula`:
+ *  - `y ~ a + b` means model `y ~ w0 + w1 * a + w2 * b` where `w0` is the intercept and `w1, w2`
+ * are coefficients.
+ *  - `y ~ a + b + a:b - 1` means model `y ~ w1 * a + w2 * b + w3 * a * b` where `w1, w2, w3`
+ * are coefficients.
+ *
+ * RFormula produces a vector column of features and a double or string column of label.
+ * Like when formulas are used in R for linear regression, string input columns will be one-hot
+ * encoded, and numeric columns will be cast to doubles.
+ * If the label column is of type string, it will be first transformed to double with
+ * `StringIndexer`. If the label column does not exist in the DataFrame, the output label column
+ * will be created from the specified response variable in the formula.
  */
 @Experimental
 class RFormula(override val uid: String) extends Estimator[RFormulaModel] with RFormulaBase {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org