Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/18742#discussion_r131332345
--- Diff: python/pyspark/ml/util.py ---
@@ -283,3 +341,198 @@ def numFeatures(self):
Returns the number of features the model was trained on. If
unknown, returns -1
"""
return self._call_java("numFeatures")
+
+
+@inherit_doc
+class DefaultParamsWritable(MLWritable):
+ """
+ .. note:: DeveloperApi
+
+ Helper trait for making simple `Params` types writable. If a `Params`
class stores
+ all data as [[pyspark.ml.param.Param]] values, then extending this
trait will provide
+ a default implementation of writing saved instances of the class.
+ This only handles simple [[pyspark.ml.param.Param]] types; e.g., it
will not handle
+ [[pyspark.sql.Dataset]].
+
+ @see `DefaultParamsReadable`, the counterpart to this trait
+
+ .. versionadded:: 2.3.0
+ """
+
+ def write(self):
+ """Returns a DefaultParamsWriter instance for this class."""
+ if isinstance(self, Params):
+ return DefaultParamsWriter(self)
+ else:
+ raise TypeError("Cannot use DefautParamsWritable with type %s
because it does not " +
+ " extend Params.", type(self))
+
+
+@inherit_doc
+class DefaultParamsWriter(MLWriter):
+ """
+ .. note:: DeveloperApi
+
+ Class for writing Estimators and Transformers whose parameters are
JSON-serializable.
+
+ .. versionadded:: 2.3.0
+ """
+
+ def __init__(self, instance):
+ super(DefaultParamsWriter, self).__init__()
+ self.instance = instance
+
+ def saveImpl(self, path):
+ DefaultParamsWriter.save_metadata(self.instance, path, self.sc)
+
+ @staticmethod
+ def save_metadata(instance, path, sc, extraMetadata=None,
paramMap=None):
--- End diff --
If this is going to be public, let's use camelCase to match style
---
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]