Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/10085#discussion_r50150766
--- Diff: python/pyspark/ml/feature.py ---
@@ -992,6 +993,88 @@ def getDegree(self):
@inherit_doc
+class QuantileDiscretizer(JavaEstimator, HasInputCol, HasOutputCol):
+ """
+ .. note:: Experimental
+
+ `QuantileDiscretizer` takes a column with continuous features and
outputs a column with binned
+ categorical features. The bin ranges are chosen by taking a sample of
the data and dividing it
+ into roughly equal parts. The lower and upper bin bounds will be
-Infinity and +Infinity,
+ covering all real values. This attempts to find numBuckets partitions
based on a sample of data,
+ but it may find fewer depending on the data sample values.
+
+ >>> df = sqlContext.createDataFrame([(0.1,), (0.4,), (1.2,), (1.5,)],
["values"])
+ >>> qds = QuantileDiscretizer(numBuckets=2,
+ ... inputCol="values", outputCol="buckets")
+ >>> bucketizer = qds.fit(df)
+ >>> splits = bucketizer.getSplits()
+ >>> splits[0]
+ -inf
+ >>> int(splits[1]*10)
+ 4
+ >>> bucketed = bucketizer.transform(df).collect()
+ >>> bucketed[0].buckets
+ 0.0
+
+ .. versionadded:: 2.0.0
+ """
+
+ # a placeholder to make it appear in the generated doc
+ numBuckets = Param(Params._dummy(), "numBuckets",
+ "Maximum number of buckets (quantiles, or " +
+ "categories) into which data points are grouped.
Must be >= 2. Default 2.")
+
+ @keyword_only
+ def __init__(self, numBuckets=2, inputCol=None, outputCol=None):
+ """
+ __init__(self, numBuckets=2, inputCol=None, outputCol=None)
+ """
+ super(QuantileDiscretizer, self).__init__()
+ self._java_obj =
self._new_java_obj("org.apache.spark.ml.feature.QuantileDiscretizer",
+ self.uid)
+ self.numBuckets = Param(self, "numBuckets",
+ "Maximum number of buckets (quantiles, or
" +
+ "categories) into which data points are
grouped. Must be >= 2.")
+ self._setDefault(numBuckets=2)
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ @since("2.0.0")
+ def setParams(self, numBuckets=2, inputCol=None, outputCol=None):
+ """
+ setParams(self, numBuckets=2, inputCol=None, outputCol=None)
+ Set the params for the QuantileDiscertizerBase
--- End diff --
typo
---
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]