Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/5991#discussion_r29917399
--- Diff: python/pyspark/ml/feature.py ---
@@ -113,6 +125,419 @@ def setParams(self, numFeatures=1 << 18,
inputCol=None, outputCol=None):
@inherit_doc
+class IDF(JavaEstimator, HasInputCol, HasOutputCol):
+ """
+ Compute the Inverse Document Frequency (IDF) given a collection of
documents.
+
+ >>> from pyspark.sql import Row
+ >>> from pyspark.mllib.linalg import DenseVector
+ >>> df = sc.parallelize([Row(tf=DenseVector([1.0, 2.0])),
+ ... Row(tf=DenseVector([0.0, 1.0])), Row(tf=DenseVector([3.0,
0.2]))]).toDF()
+ >>> idf = IDF(minDocFreq=3, inputCol="tf", outputCol="idf")
+ >>> idf.fit(df).transform(df).head().idf
+ DenseVector([0.0, 0.0])
+ >>>
idf.setParams(outputCol="freqs").fit(df).transform(df).collect()[1].freqs
+ DenseVector([0.0, 0.0])
+ >>> params = {idf.minDocFreq: 1, idf.outputCol: "vector"}
+ >>> idf.fit(df, params).transform(df).head().vector
+ DenseVector([0.2877, 0.0])
+ """
+
+ _java_class = "org.apache.spark.ml.feature.IDF"
+
+ # a placeholder to make it appear in the generated doc
+ minDocFreq = Param(Params._dummy(), "minDocFreq",
+ "minimum of documents in which a term should appear
for filtering")
+
+ @keyword_only
+ def __init__(self, minDocFreq=0, inputCol=None, outputCol=None):
+ """
+ __init__(self, minDocFreq=0, inputCol=None, outputCol=None)
+ """
+ super(IDF, self).__init__()
+ self.minDocFreq = Param(self, "minDocFreq",
+ "minimum of documents in which a term
should appear for filtering")
+ self._setDefault(minDocFreq=0)
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ def setParams(self, minDocFreq=0, inputCol=None, outputCol=None):
+ """
+ setParams(self, minDocFreq=0, inputCol=None, outputCol=None)
+ Sets params for this IDF.
+ """
+ kwargs = self.setParams._input_kwargs
+ return self._set(**kwargs)
+
+ def setMinDocFreq(self, value):
+ """
+ Sets the value of :py:attr:`minDocFreq`.
+ """
+ self.paramMap[self.minDocFreq] = value
+ return self
+
+ def getMinDocFreq(self):
+ """
+ Gets the value of minDocFreq or its default value.
+ """
+ return self.getOrDefault(self.minDocFreq)
+
+
+class IDFModel(JavaModel):
+ """
+ Model fitted by IDF.
+ """
+
+
+@inherit_doc
+class Normalizer(JavaTransformer, HasInputCol, HasOutputCol):
+ """
+ Normalize a vector to have unit norm using the given p-norm.
+
+ >>> from pyspark.mllib.linalg import Vectors
+ >>> from pyspark.sql import Row
+ >>> svec = Vectors.sparse(4, {1: 4.0, 3: 3.0})
+ >>> df = sc.parallelize([Row(dense=Vectors.dense([3.0, -4.0]),
sparse=svec)]).toDF()
+ >>> Normalizer = Normalizer(p=2.0, inputCol="dense",
outputCol="features")
--- End diff --
the first `Normalizer` -> `normalizer`
---
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]