1
我寫了一個分類器與mahout樸素貝葉斯分類器。來自classifyfull方法的返回值都是0或負數。這些是什麼意思?
和分類器的作品,但我需要知道評分的每個類別的百分比。換句話說,如何知道輸入與類別匹配的百分比。mahout樸素貝葉斯分類百分比
下面是一段代碼塊。感謝所有回覆。
Vector vector = new RandomAccessSparseVector(10000);
TFIDF tfidf = new TFIDF();
for (Multiset.Entry<String> entry : words.entrySet()) {
String word = entry.getElement();
int count = entry.getCount();
Integer wordId = getDictionary().get(word);
Long freq = getDocumentFrequency().get(wordId);
double tfIdfValue = tfidf.calculate(count, freq.intValue(), wordCount, getDocumentFrequency().size());
vector.setQuick(wordId, tfIdfValue);
}
Vector resultVector = classifier.classifyFull(vector);
double bestScore = -Double.MAX_VALUE;
int bestCategoryId = -1;
for (Vector.Element element : resultVector.all()) {
int categoryId = element.index();
double score = element.get();
detailhits.add(new CategoryScore(labels.get(categoryId),score));
if (score > bestScore) {
bestScore = score;
bestCategoryId = categoryId;
}
//System.out.print(" " + labels.get(categoryId) + ": " + score);
}