Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5991#discussion_r29917404
  
    --- 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")
    +    >>> model = StringIndexer.fit(stringIndDf)
    +    >>> td = model.transform(stringIndDf)
    +    >>> encoder = OneHotEncoder(includeFirst=False, inputCol="indexed", 
outputCol="features")
    +    >>> encoder.transform(td).head().features
    +    SparseVector(2, {})
    +    >>> encoder.setParams(outputCol="freqs").transform(td).head().freqs
    +    SparseVector(2, {})
    +    >>> params = {encoder.includeFirst: True, encoder.outputCol: "test"}
    +    >>> encoder.transform(td, params).head().test
    +    SparseVector(3, {0: 1.0})
    +    """
    +
    +    _java_class = "org.apache.spark.ml.feature.OneHotEncoder"
    +
    +    # a placeholder to make it appear in the generated doc
    +    includeFirst = Param(Params._dummy(), "includeFirst", "include first 
category")
    +
    +    @keyword_only
    +    def __init__(self, includeFirst=True, inputCol=None, outputCol=None):
    +        """
    +        __init__(self, includeFirst=True, inputCol=None, outputCol=None)
    +        """
    +        super(OneHotEncoder, self).__init__()
    +        self.includeFirst = Param(self, "includeFirst", "include first 
category")
    +        self._setDefault(includeFirst=True)
    +        kwargs = self.__init__._input_kwargs
    +        self.setParams(**kwargs)
    +
    +    @keyword_only
    +    def setParams(self, includeFirst=True, inputCol=None, outputCol=None):
    +        """
    +        setParams(self, includeFirst=True, inputCol=None, outputCol=None)
    +        Sets params for this OneHotEncoder.
    +        """
    +        kwargs = self.setParams._input_kwargs
    +        return self._set(**kwargs)
    +
    +    def setIncludeFirst(self, value):
    +        """
    +        Sets the value of :py:attr:`includeFirst`.
    +        """
    +        self.paramMap[self.includeFirst] = value
    +        return self
    +
    +    def getIncludeFirst(self):
    +        """
    +        Gets the value of includeFirst or its default value.
    +        """
    +        return self.getOrDefault(self.includeFirst)
    +
    +
    +@inherit_doc
    +class PolynomialExpansion(JavaTransformer, HasInputCol, HasOutputCol):
    +    """
    +    Perform feature expansion in a polynomial space. As said in wikipedia 
of Polynomial Expansion,
    +    which is available at 
`http://en.wikipedia.org/wiki/Polynomial_expansion`, "In mathematics, an
    +    expansion of a product of sums expresses it as a sum of products by 
using the fact that
    +    multiplication distributes over addition". Take a 2-variable feature 
vector as an example:
    +    `(x, y)`, if we want to expand it with degree 2, then we get `(x, x * 
x, y, x * y, y * y)`.
    +
    +    >>> from pyspark.mllib.linalg import Vectors
    +    >>> from pyspark.sql import Row
    +    >>> df = sc.parallelize([Row(dense=Vectors.dense([0.5, 2.0]))]).toDF()
    +    >>> px = PolynomialExpansion(degree=2, inputCol="dense", 
outputCol="expanded")
    +    >>> px.transform(df).head().expanded
    +    DenseVector([0.5, 0.25, 2.0, 1.0, 4.0])
    +    >>> px.setParams(outputCol="test").transform(df).head().test
    +    DenseVector([0.5, 0.25, 2.0, 1.0, 4.0])
    +    """
    +
    +    _java_class = "org.apache.spark.ml.feature.PolynomialExpansion"
    +
    +    # a placeholder to make it appear in the generated doc
    +    degree = Param(Params._dummy(), "degree", "the polynomial degree to 
expand (>= 1)")
    +
    +    @keyword_only
    +    def __init__(self, degree=2, inputCol=None, outputCol=None):
    +        """
    +        __init__(self, degree=2, inputCol=None, outputCol=None)
    +        """
    +        super(PolynomialExpansion, self).__init__()
    +        self.degree = Param(self, "degree", "the polynomial degree to 
expand (>= 1)")
    +        self._setDefault(degree=2)
    +        kwargs = self.__init__._input_kwargs
    +        self.setParams(**kwargs)
    +
    +    @keyword_only
    +    def setParams(self, degree=2, inputCol=None, outputCol=None):
    +        """
    +        setParams(self, degree=2, inputCol=None, outputCol=None)
    +        Sets params for this PolynomialExpansion.
    +        """
    +        kwargs = self.setParams._input_kwargs
    +        return self._set(**kwargs)
    +
    +    def setDegree(self, value):
    +        """
    +        Sets the value of :py:attr:`degree`.
    +        """
    +        self.paramMap[self.degree] = value
    +        return self
    +
    +    def getDegree(self):
    +        """
    +        Gets the value of degree or its default value.
    +        """
    +        return self.getOrDefault(self.degree)
    +
    +
    +@inherit_doc
    +class StandardScaler(JavaEstimator, HasInputCol, HasOutputCol):
    +    """
    +    Standardizes features by removing the mean and scaling to unit 
variance using column summary
    +    statistics on the samples in the training set.
    +
    +    >>> from pyspark.mllib.linalg import Vectors
    +    >>> from pyspark.sql import Row
    +    >>> df = sc.parallelize([Row(a=Vectors.dense([0.0])), 
Row(a=Vectors.dense([2.0]))]).toDF()
    +    >>> StandardScaler = StandardScaler(inputCol="a", outputCol="scaled")
    +    >>> model = StandardScaler.fit(df)
    +    >>> model.transform(df).collect()[1].scaled
    +    DenseVector([1.4142])
    +    """
    +
    +    _java_class = "org.apache.spark.ml.feature.StandardScaler"
    +
    +    # a placeholder to make it appear in the generated doc
    +    withMean = Param(Params._dummy(), "withMean", "Center data with mean")
    +    withStd = Param(Params._dummy(), "withStd", "Scale to unit standard 
deviation")
    +
    +    @keyword_only
    +    def __init__(self, withMean=False, withStd=True, inputCol=None, 
outputCol=None):
    +        """
    +        __init__(self, withMean=False, withStd=True, inputCol=None, 
outputCol=None)
    +        """
    +        super(StandardScaler, self).__init__()
    +        self.withMean = Param(self, "withMean", "Center data with mean")
    +        self.withStd = Param(self, "withStd", "Scale to unit standard 
deviation")
    +        self._setDefault(withMean=False, withStd=True)
    +        kwargs = self.__init__._input_kwargs
    +        self.setParams(**kwargs)
    +
    +    @keyword_only
    +    def setParams(self, withMean=False, withStd=True, inputCol=None, 
outputCol=None):
    +        """
    +        setParams(self, withMean=False, withStd=True, inputCol=None, 
outputCol=None)
    +        Sets params for this StandardScaler.
    +        """
    +        kwargs = self.setParams._input_kwargs
    +        return self._set(**kwargs)
    +
    +    def setWithMean(self, value):
    +        """
    +        Sets the value of :py:attr:`withMean`.
    +        """
    +        self.paramMap[self.withMean] = value
    +        return self
    +
    +    def getWithMean(self):
    +        """
    +        Gets the value of withMean or its default value.
    +        """
    +        return self.getOrDefault(self.withMean)
    +
    +    def setWithStd(self, value):
    +        """
    +        Sets the value of :py:attr:`withStd`.
    +        """
    +        self.paramMap[self.withStd] = value
    +        return self
    +
    +    def getWithStd(self):
    +        """
    +        Gets the value of withStd or its default value.
    +        """
    +        return self.getOrDefault(self.withStd)
    +
    +
    +class StandardScalerModel(JavaModel):
    +    """
    +    Model fitted by StandardScaler.
    +    """
    +
    +
    +@inherit_doc
    +class StringIndexer(JavaEstimator, HasInputCol, HasOutputCol):
    +    """
    +    A label indexer that maps a string column of labels to an ML column of 
label indices.
    +    If the input column is numeric, we cast it to string and index the 
string values.
    +    The indices are in [0, numLabels), ordered by label frequencies.
    +    So the most frequent label gets index 0.
    +
    +    >>> 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]

Reply via email to