[ 
https://issues.apache.org/jira/browse/SPARK-14497?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Joseph K. Bradley updated SPARK-14497:
--------------------------------------
    Summary: Use top instead of sortBy() to get top N frequent words as dict in 
CountVectorizer  (was: Use top instead of sortBy() to get top N frequent words 
as dict in ConutVectorizer)

> Use top instead of sortBy() to get top N frequent words as dict in 
> CountVectorizer
> ----------------------------------------------------------------------------------
>
>                 Key: SPARK-14497
>                 URL: https://issues.apache.org/jira/browse/SPARK-14497
>             Project: Spark
>          Issue Type: Improvement
>          Components: ML
>            Reporter: Feng Wang
>            Assignee: Feng Wang
>             Fix For: 2.0.0
>
>
> It's not necessary to sort the whole rdd to get top n frequent words.
>         // Sort terms to select vocab
>         wordCounts.sortBy(_._2, ascending = false).take(vocSize)
>       
> we could use top() instead since: 
> top - O ( n )
> sortBy - O (n*logn)
> A minor side effect introduced by top() using default implicit Ordering in 
> Tuple2: 
> if the terms with same TF in dictionary would be sorted in descending order.
> (a:1), (b:1),(c:1)  => dict: [c, b, a]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to