Tf-idf, or term frequency-inverse document frequency, is a statistic that indicates how important a word is to the entire document. This lesson will explain term frequency and inverse document frequency, and show how we can use tf-idf to identify the most relevant words in a body of text.

Find specific words tf-idf for given documents:

var natural = require('natural');
var TfIdf = natural.TfIdf;
var tfidf = new TfIdf(); tfidf.addDocument('this document is about node.');
tfidf.addDocument('this document is about ruby.');
tfidf.addDocument('this document is about ruby and node.'); tfidf.tfidfs('node ruby', function(i, measure) {
console.log('document #' + i + ' is ' + measure);
}); /*
document #0 is 1
document #1 is 1
document #2 is 2
*/

List most important words:

tfidf.listTerms(0 /*document index*/).forEach(function(item) {
console.log(item.term + ': ' + item.tfidf);
});

[Javascript] Identify the most important words in a document using tf-idf in Natural的更多相关文章

  1. [Javascript] Identify and Deal with NaN in JavaScript

    Dealing with the special NaN value can be tricky in JavaScript. It behaves like a number and not a n ...

  2. javascript的window.onload()方法和jQuery的$(document).ready()的对比

    jQuery中$(document).ready()的作用类似于传统JavaScript中的window.onload方法,不过与window.onload方法还是有区别的. 1.执行时间 windo ...

  3. JavaScript常用内置对象(window、document、form对象)

    由于刚开始学习B/S编程,下面对各种脚本语言有一个宏观的简单认识. 脚本语言(JavaScript,Vbscript,JScript等)介于HTML和C,C++,Java,C#等编程语言之间.它的优势 ...

  4. JavaScript -- 时光流逝(十一):DOM -- Document 对象

    JavaScript -- 知识点回顾篇(十一):DOM -- Document 对象 (1) document.activeElement: 返回文档中当前获得焦点的元素. <!doctype ...

  5. Javascript中只能在 HTML 输出流中使用 document.write,在文档已加载后使用它(比如在函数中),会覆盖整个文档。

    意思就是说,初次加载时如果没有加载document.write,那么再次加载的时候回覆盖掉原来的内容,只显示新加载的内容. <!DOCTYPE html> <html> < ...

  6. electron项目踩坑--A JavaScript error occurred in the main process:document is not defined

    前言 记录electron-vue项目开发中遇到的一个错误,运行时报错如图: 控制台报错如下: ReferenceError: document is not defined at Object.&l ...

  7. ES搜索排序,文档相关度评分介绍——TF-IDF—term frequency, inverse document frequency, and field-length norm—are calculated and stored at index time.

    Theory Behind Relevance Scoring Lucene (and thus Elasticsearch) uses the Boolean model to find match ...

  8. JavaScript之DOM等级概述

    这两日对DOM等级的理解不是太通透,就进Mozilla官网去看了一下,然后进行了首次的对技术文档的翻译工作,虽然官网也有中文解释,但我想,自己翻译出来时,已经有了原汁原味的理解了吧,这边是做此次翻译的 ...

  9. 6、JavaScript进阶篇③——浏览器对象、Dom对象

    一.浏览器对象 1. window对象 window对象是BOM的核心,window对象指当前的浏览器窗口. window对象方法: 注意:在JavaScript基础篇中,已讲解了部分属性,windo ...

随机推荐

  1. 20180929 北京大学 人工智能实践:Tensorflow笔记03

    更改的程序部分如下: 另: 难?????????????见链接: https://www.bilibili.com/video/av22530538/?p=17 + (完)

  2. P2633 Count on a tree(主席树)

    题目描述 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个 ...

  3. SPOJ 694 Distinct Substrings

    Distinct Substrings Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on SPOJ. O ...

  4. zookeeper_相关命令 以及 API

    (区分大小写) 启动ZooKeeper服务        进入主目录下的 /bin 文件夹. zkServer.sh start.  需要每个节点运行启动命令 客户端启动          zkCli ...

  5. NYOJ_77 开灯问题

    题目地址 分析: 用一个数组来保存每盏灯的操作的次数.推断奇偶就可以推断灯的状态. 最后的输出格式须要注意一下空格的位置,思路就是现输出一个.剩下来的输出在前面加一个空格. 空格用_表示: 1_3_5 ...

  6. RenderScript on LLVM笔记

    Android 为何引入 Render Script: 3D 可移植  ( 直接用 opengl 也能够移植呀?) 性能 易用性 ( 让 opengl 难入门的人,用 Render Script ?) ...

  7. Eclipse下面的Maven管理的SSH框架整合(Struts,Spring,Hibernate)

    搭建的环境:eclispe下面的maven web项目 Struts:    2.5.10 Spring:    4.3.8 Hibernate:   5.1.7 .Final MySQL:   5. ...

  8. poj--2391--Ombrophobic Bovines(floyd+二分+最大流拆点)

    Ombrophobic Bovines Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u ...

  9. 流量数据iftop命令

    yum install flex byacc libpcap ncurses ncurses-devel libpcap-devel tar zxvf iftop-0.17.tar.gz cd ift ...

  10. C#泛型链表Demo

    /// <summary> /// 节点 /// </summary> /// <typeparam name="T"></typepar ...