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

    https://github.com/apache/spark/pull/2819#discussion_r19436372
  
    --- Diff: docs/mllib-feature-extraction.md ---
    @@ -95,8 +95,50 @@ tf.cache()
     val idf = new IDF(minDocFreq = 2).fit(tf)
     val tfidf: RDD[Vector] = idf.transform(tf)
     {% endhighlight %}
    +</div>
    +<div data-lang="python" markdown="1">
    +
    +TF and IDF are implemented in 
[HashingTF](api/python/pyspark.mllib.html#pyspark.mllib.feature.HashingTF)
    +and [IDF](api/python/pyspark.mllib.html#pyspark.mllib.feature.IDF).
    +`HashingTF` takes an RDD of list as the input.
    +Each record could be an iterable of strings or other types.
    +
    +{% highlight python %}
    +from pyspark import SparkContext
    +from pyspark.mllib.linalg import Vector
    +from pyspark.mllib.feature import HashingTF
    +
    +sc = SparkContext()
    +
    +# Load documents (one per line).
    +documents = sc.textFile("...").map(lambda line: line.split(" "))
    +
    +hashingTF = HashingTF()
    +tf = hashingTF.transform(documents)
    +{% endhighlight %}
    +
    +While applying `HashingTF` only needs a single pass to the data, applying 
`IDF` needs two passes: 
    +first to compute the IDF vector and second to scale the term frequencies 
by IDF.
    +
    +{% highlight python %}
    +from pyspark.mllib.feature import IDF
    +
    +# ... continue from the previous example
    +tf.cache()
    +idf = IDF().fit(tf)
    +tfidf = idf.transform(tf)
    +{% endhighlight %}
     
    +MLLib's IDF implementation provides an option for ignoring terms which 
occur in less than a
    +minimum number of documents.  In such cases, the IDF for these terms is 
set to 0.  This feature
    +can be used by passing the `minDocFreq` value to the IDF constructor.
     
    +{% highlight python %}
    +# ... continue from the previous example
    +tf.cache()
    +idf = IDF().fit(tf)
    --- End diff --
    
    This is supposed to be an example of explicitly setting minDocFreq.  Please 
compare with the Scala example.


---
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