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

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Javascript] Identify the most important words in a document using tf-idf in Natural相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

How to identify the LUN IDs for SAN disks of 3PAR

论文阅读 | Employing the Correspondence of Relations and Connectives to Identify Implicit Discourse Rela

Springboot异常--Identify and stop the process that‘s listening on port 9090 or configure this applicat

解决:Unable to identify index name. XXXModel is not a Document. Make sure the document class is annota

identity 和 identify (我分不清)

Rails 3 和 Paperclip:“'identify' 命令无法识别”