Feature Transformation -- RFormula (Estimator)
Implements the transforms required for fitting a dataset against an R model
formula. Currently we support a limited subset of the R operators,
-. Also see the R formula docs here:
ft_r_formula(x, formula = NULL, features_col = "features", label_col = "label", force_index_label = FALSE, uid = random_string("r_formula_"), ...)
R formula as a character string or a formula. Formula objects are converted to character strings directly and the environment is not captured.
Features column name, as a length-one character vector. The column should be single vector column of numeric values. Usually this column is output by
Label column name. The column should be a numeric column. Usually this column is output by
(Spark 2.1.0+) Force to index label whether it is numeric or
string type. Usually we index label only when it is string type. If
the formula was used by classification algorithms, we can force to index
label even it is numeric type by setting this param with true.
A character string used to uniquely identify the feature transformer.
Optional arguments; currently unused.
The object returned depends on the class of
spark_connection, the function returns a
ml_estimator, or one of their subclasses. The object contains a pointer to a Spark
Estimatorobject and can be used to compose
ml_pipeline, the function returns a
ml_pipelinewith the transformer or estimator appended to the pipeline.
tbl_spark, a transformer is constructed then immediately applied to the input
tbl_spark, returning a
The basic operators in the formula 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 + bmeans model
y ~ w0 + w1 * a + w2 * bwhere
w0is the intercept and
w1, w2are coefficients.
y ~ a + b + a:b - 1means model
y ~ w1 * a + w2 * b + w3 * a * bwhere
w1, w2, w3are 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.
In the case where
x is a
tbl_spark, the estimator fits against
to obtain a transformer, which is then immediately used to transform
x, returning a
See http://spark.apache.org/docs/latest/ml-features.html for more information on the set of transformations available for DataFrame columns in Spark.
Other feature transformers: