码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Identify the most important words in a document using tf-idf in Natural

时间:2017-10-03 21:11:33      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:cat   index   class   listt   port   ica   less   each   use   

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

标签:cat   index   class   listt   port   ica   less   each   use   

原文地址:http://www.cnblogs.com/Answer1215/p/7624434.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!