我想规范化我从这个给定代码中得到的 tfidf 结果:
for (int docNum = 0; docNum < ir.numDocs(); docNum++) {
TermFreqVector tfv = ir.getTermFreqVector(docNum, "contents");
if (tfv == null) {
// ignore empty fields
continue;
}
String[] tterms = tfv.getTerms();
int termCount = tterms.length;
int[] freqs = tfv.getTermFrequencies();
for (int t = 0; t < termCount; t++) {
double idf = ir.numDocs() / ir.docFreq(new Term("contents", tterms[t]));
System.out.println(" " + tterms[t] + " " + freqs[t]*Math.log(idf));
}
}
此代码的输出是:
area 0.0
areola 5.877735781779639
ari 3.9318256327243257
art 1.6094379124341003
artifici 1.0986122886681098
assign 2.1972245773362196
associ 3.295836866004329
assur 1.9459101490553132
averag 1.0986122886681098
avoid 0.6931471805599453
.
.
.
任何帮助将非常感激。谢谢你