diff options
Diffstat (limited to 'python/pyspark/ml/feature.py')
-rw-r--r-- | python/pyspark/ml/feature.py | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/python/pyspark/ml/feature.py b/python/pyspark/ml/feature.py index 5025493c42..3182faac0d 100644 --- a/python/pyspark/ml/feature.py +++ b/python/pyspark/ml/feature.py @@ -2360,7 +2360,7 @@ class PCAModel(JavaModel, MLReadable, MLWritable): @inherit_doc -class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): +class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol, MLReadable, MLWritable): """ .. note:: Experimental @@ -2376,7 +2376,8 @@ class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): ... (0.0, 0.0, "a") ... ], ["y", "x", "s"]) >>> rf = RFormula(formula="y ~ x + s") - >>> rf.fit(df).transform(df).show() + >>> model = rf.fit(df) + >>> model.transform(df).show() +---+---+---+---------+-----+ | y| x| s| features|label| +---+---+---+---------+-----+ @@ -2394,6 +2395,29 @@ class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): |0.0|0.0| a| [0.0]| 0.0| +---+---+---+--------+-----+ ... + >>> rFormulaPath = temp_path + "/rFormula" + >>> rf.save(rFormulaPath) + >>> loadedRF = RFormula.load(rFormulaPath) + >>> loadedRF.getFormula() == rf.getFormula() + True + >>> loadedRF.getFeaturesCol() == rf.getFeaturesCol() + True + >>> loadedRF.getLabelCol() == rf.getLabelCol() + True + >>> modelPath = temp_path + "/rFormulaModel" + >>> model.save(modelPath) + >>> loadedModel = RFormulaModel.load(modelPath) + >>> loadedModel.uid == model.uid + True + >>> loadedModel.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| + +---+---+---+---------+-----+ + ... .. versionadded:: 1.5.0 """ @@ -2439,7 +2463,7 @@ class RFormula(JavaEstimator, HasFeaturesCol, HasLabelCol): return RFormulaModel(java_model) -class RFormulaModel(JavaModel): +class RFormulaModel(JavaModel, MLReadable, MLWritable): """ .. note:: Experimental |