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. 使用glPushMatrix和glPopMatrix的原因

    转自 百度百科   glPushMatrix 函数将当前矩阵堆栈推送,通过一个,复制当前矩阵. 这就是后 glPushMatrix 的调用堆栈的顶部矩阵是它下面的相同的.   1. 原理讲解 终于明白 ...

  2. 常量成员函数的注意事项 & mutable的使用场景

    mutable的使用场景: 可以在一个const的对象里面,解除对部分字段的const限制.也可以用在const成员函数里面. 对于const与否,一般会调用不同版本的函数: 而对于二元操作符,如果用 ...

  3. POJ - 3984 - 迷宫问题 (DFS)

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10936   Accepted: 6531 Description ...

  4. URAL 1823. Ideal Gas(数学啊 )

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time limit: 0.5 second Me ...

  5. VGA接口时序约束

    SF-VGA模块板载VGA显示器DA转换驱动芯片AVD7123,FPGA通过OUPLLN连接器驱动ADV7123芯片产生供给VGA显示器的色彩以及同步信号.SF-CY3核心模块与SF-VGA子模块连接 ...

  6. url与图片

    http://restapi.amap.com/v3/staticmap?location=116.481485,39.990464&zoom=10&size=750*300& ...

  7. 直播聊天室,点亮效果,jquery实现

    1.css #like_area img{ width: 30px; height: 30px; position: absolute; bottom: 100px; left: 60%; margi ...

  8. Linux下配置Squid基础教程

    Linux下配置Squid基础教程 本视频高清下载地址:http://down.51cto.com/data/437529 本文出自 "李晨光原创技术博客" 博客,请务必保留此出处 ...

  9. 【转】Android应用底部导航栏(选项卡)实例

    现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其 ...

  10. Conventions and patterns for multi-platform development

    For Developers‎ > ‎Design Documents‎ > ‎ Conventions and patterns for multi-platform developme ...