You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Feng Wang (JIRA)" <ji...@apache.org> on 2016/04/08 22:29:25 UTC
[jira] [Created] (SPARK-14497) Use top instead of sortBy() to get
top N frequent words as dict in ConutVectorizer
Feng Wang created SPARK-14497:
---------------------------------
Summary: 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(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]
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org