知识卡片
按字段排序需明确提取位置
字典items产生键值对,按每个二元组第二项排序可得到按数值排名的列表。itemgetter(1)提取的是位置1,不是按字段名称或第一项排序;reverse=True改变排序方向。它决定展示次序,不会重新计算计数或保证相同计数有业务上有意义的先后。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 3 处
- · 查看原书依据
key=itemgetter(1)传递给sorted函数将会返回基于元组第二项字段进行排序的有序列表。详细内容见附录C。 示例2-10:计算每个好友的“赞”数量,并根据频率进行排序 # Build a frequency distribution of number of likes by # friend with a dictionary compreh
- · 查看原书依据
sorted(query_scores.items()): print doc, score 样例输出如下: a : Mr. Green killed Colonel Mustard in the study... b : Professor Plum has a green plant in his study. c : Miss Scarlett wat
- · 查看原书依据
top_n_words = [w[0] for w in fdist.items() if w[0] not in nltk.corpus.stopwords.words('english')][:N] scored_sentences = _score_sentences(normalized_sentences, top_n_words) # Summa
参考来源
- 位置:《社交网站的数据挖掘与分析(原书第2版)》第2章《2.3.2 查看好友关系》(spine72;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0061.html;u038-ch02-023)。
- 结论依据:原文在“key=itemgetter(1)”附近的定义、例子或代码支撑本卡核心说明:字典items产生键值对,按每个二元组第二项排序可得到按数值排名的列表。边界按已读前提解释;示例未执行。
- 原始内容:key=itemgetter(1)传递给sorted函数将会返回基于元组第二项字段进行排序的有序列表。详细内容见附录C。 示例2-10:计算每个好友的“赞”数量,并根据频率进行排序 # Build a frequency distribution of number of likes by # friend with a dictionary compreh
- 位置:《社交网站的数据挖掘与分析(原书第2版)》第4章《4.3.3 TF-IDF》(spine86;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0075.html;u062-ch02-023)。
- 结论依据:样例末尾默认排序字典键,显示a/b/c不是按相关性分数降序;后面的NLTK例子才显式按score排序。
- 原始内容:sorted(query_scores.items()): print doc, score 样例输出如下: a : Mr. Green killed Colonel Mustard in the study... b : Professor Plum has a green plant in his study. c : Miss Scarlett wat
- 位置:《社交网站的数据挖掘与分析(原书第2版)》第5章《5.3.3 文档摘要》(spine94;extracted/OReilly精品图书系列共21册(《Javascript权威指南》、《机器学习:实用案例解析》、《编写可读代码的艺术》、《算法精解》等)/_epub-src/text/part0083.html;u079-ch02-023)。
- 结论依据:用items前N项作为高频词需确认频序,移植时应显式依据计数选取。
- 原始内容:top_n_words = [w[0] for w in fdist.items() if w[0] not in nltk.corpus.stopwords.words('english')][:N] scored_sentences = _score_sentences(normalized_sentences, top_n_words) # Summa