Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/5991#discussion_r29917401
--- 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")
+ >>> Normalizer.transform(df).head().features
+ DenseVector([0.6, -0.8])
+ >>> Normalizer.setParams(inputCol="sparse",
outputCol="freqs").transform(df).head().freqs
+ SparseVector(4, {1: 0.8, 3: 0.6})
+ >>> params = {Normalizer.p: 1.0, Normalizer.inputCol: "dense",
Normalizer.outputCol: "vector"}
+ >>> Normalizer.transform(df, params).head().vector
+ DenseVector([0.4286, -0.5714])
+ """
+
+ # a placeholder to make it appear in the generated doc
+ p = Param(Params._dummy(), "p", "the p norm value.")
+
+ _java_class = "org.apache.spark.ml.feature.Normalizer"
+
+ @keyword_only
+ def __init__(self, p=2.0, inputCol=None, outputCol=None):
+ """
+ __init__(self, p=2.0, inputCol=None, outputCol=None)
+ """
+ super(Normalizer, self).__init__()
+ self.p = Param(self, "p", "the p norm value.")
+ self._setDefault(p=2.0)
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ def setParams(self, p=2.0, inputCol=None, outputCol=None):
+ """
+ setParams(self, p=2.0, inputCol=None, outputCol=None)
+ Sets params for this Normalizer.
+ """
+ kwargs = self.setParams._input_kwargs
+ return self._set(**kwargs)
+
+ def setP(self, value):
+ """
+ Sets the value of :py:attr:`p`.
+ """
+ self.paramMap[self.p] = value
+ return self
+
+ def getP(self):
+ """
+ Gets the value of p or its default value.
+ """
+ return self.getOrDefault(self.p)
+
+
+@inherit_doc
+class OneHotEncoder(JavaTransformer, HasInputCol, HasOutputCol):
+ """
+ A one-hot encoder that maps a column of label indices to a column of
binary vectors, with
+ at most a single one-value. By default, the binary vector has an
element for each category, so
+ with 5 categories, an input value of 2.0 would map to an output vector
of
+ (0.0, 0.0, 1.0, 0.0, 0.0). If includeFirst is set to false, the first
category is omitted, so
+ the output vector for the previous example would be (0.0, 1.0, 0.0,
0.0) and an input value
+ of 0.0 would map to a vector of all zeros. Including the first
category makes the vector columns
+ linearly dependent because they sum up to one.
+
+ TODO: This method requires the use of StringIndexer first. Decouple
them.
+
+ >>> StringIndexer = StringIndexer(inputCol="label",
outputCol="indexed")
--- End diff --
`StringIndexer` -> `stringIndexer`
---
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]