Github user MechCoder commented on a diff in the pull request:
https://github.com/apache/spark/pull/7879#discussion_r36061054
--- Diff: python/pyspark/ml/feature.py ---
@@ -1110,6 +1110,80 @@ class PCAModel(JavaModel):
"""
+@inherit_doc
+class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol):
+ """
+ .. note:: Experimental
+
+ 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:
+ http://stat.ethz.ch/R-manual/R-patched/library/stats/html/formula.html
+
+ >>> df = sqlContext.createDataFrame([
+ ... (1.0, 1.0, "a"),
+ ... (0.0, 2.0, "b"),
+ ... (0.0, 0.0, "a")
+ ... ], ["y", "x", "s"])
+ >>> rf = RFormula(formula="y ~ x + s")
+ >>> rf.fit(df).transform(df).show()
+ +---+---+---+---------+-----+
+ | y| x| s| features|label|
+ +---+---+---+---------+-----+
+ |1.0|1.0| a|[1.0,1.0]| 1.0|
+ |0.0|2.0| b|[2.0,0.0]| 0.0|
+ |0.0|0.0| a|[0.0,1.0]| 0.0|
+ +---+---+---+---------+-----+
+ ...
+ """
+
+ # a placeholder to make it appear in the generated doc
+ formula = Param(Params._dummy(), "formula", "R model formula")
+
+ @keyword_only
+ def __init__(self, formula=None, featuresCol="features",
labelCol="label"):
+ """
+ __init__(self, formula=None, featuresCol="features",
labelCol="label")
+ """
+ super(RFormula, self).__init__()
+ self._java_obj =
self._new_java_obj("org.apache.spark.ml.feature.RFormula", self.uid)
+ self.formula = Param(self, "formula", "R model formula")
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ def setParams(self, formula=None, featuresCol="features",
labelCol="label"):
+ """
+ setParams(self, formula=None, featuresCol="features",
labelCol="label")
+ Sets params for RFormula.
+ """
+ kwargs = self.setParams._input_kwargs
+ return self._set(**kwargs)
+
+ def setFormula(self, value):
+ """
+ Sets the value of :py:attr:`formula`.
+ """
--- End diff --
Is it useful to check if value is a string or not?
---
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]