[ https://issues.apache.org/jira/browse/SPARK-14497?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Feng Wang updated SPARK-14497: ------------------------------ Description: 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] was: 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(n) - 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] > Use top instead of sortBy() to get top N frequent words as dict in > ConutVectorizer > ---------------------------------------------------------------------------------- > > Key: SPARK-14497 > URL: https://issues.apache.org/jira/browse/SPARK-14497 > Project: Spark > Issue Type: Improvement > Components: ML > Reporter: Feng Wang > > 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