首页 > 编程语言 > 详细

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

时间:2017-10-03 20:58:10      阅读:263      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!