本文整理汇总了Java中cc.mallet.cluster.Clustering.getNumClusters方法的典型用法代码示例。如果您正苦于以下问题:Java Clustering.getNumClusters方法的具体用法?Java Clustering.getNumClusters怎么用?Java Clustering.getNumClusters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.cluster.Clustering
的用法示例。
在下文中一共展示了Clustering.getNumClusters方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getEvaluationScores
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
@Override
public double[] getEvaluationScores(Clustering truth, Clustering predicted) {
// Precision = \sum_i [ |siprime| - |pOfsiprime| ] / \sum_i [ |siprime| - 1 ]
// where siprime is a predicted cluster, pOfsiprime is the set of
// true clusters that contain elements of siprime.
int numerator = 0;
int denominator = 0;
for (int i = 0; i < predicted.getNumClusters(); i++) {
int[] siprime = predicted.getIndicesWithLabel(i);
HashSet<Integer> pOfsiprime = new HashSet<Integer>();
for (int j = 0; j < siprime.length; j++)
pOfsiprime.add(truth.getLabel(siprime[j]));
numerator += siprime.length - pOfsiprime.size();
denominator += siprime.length - 1;
}
precisionNumerator += numerator;
precisionDenominator += denominator;
double precision = (double)numerator / denominator;
// Recall = \sum_i [ |si| - |pOfsi| ] / \sum_i [ |si| - 1 ]
// where si is a true cluster, pOfsi is the set of predicted
// clusters that contain elements of si.
numerator = denominator = 0;
for (int i = 0; i < truth.getNumClusters(); i++) {
int[] si = truth.getIndicesWithLabel(i);
HashSet<Integer> pOfsi = new HashSet<Integer>();
for (int j = 0; j < si.length; j++)
pOfsi.add(new Integer(predicted.getLabel(si[j])));
numerator += si.length - pOfsi.size();
denominator += si.length - 1;
}
recallNumerator += numerator;
recallDenominator += denominator;
double recall = (double)numerator / denominator;
return new double[]{precision,recall,(2 * precision * recall / (precision + recall))};
}
示例2: getEvaluationScores
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
@Override
public double[] getEvaluationScores(Clustering truth, Clustering predicted) {
int tp, fn, fp;
tp = fn = fp = 0;
for (int i = 0; i < predicted.getNumClusters(); i++) {
int[] predIndices = predicted.getIndicesWithLabel(i);
for (int j = 0; j < predIndices.length; j++)
for (int k = j + 1; k < predIndices.length; k++)
if (truth.getLabel(predIndices[j]) == truth.getLabel(predIndices[k]))
tp++;
else
fp++;
}
for (int i = 0; i < truth.getNumClusters(); i++) {
int[] trueIndices = truth.getIndicesWithLabel(i);
for (int j = 0; j < trueIndices.length; j++)
for (int k = j + 1; k < trueIndices.length; k++)
if (predicted.getLabel(trueIndices[j]) != predicted.getLabel(trueIndices[k]))
fn++;
}
double pr = (double)tp / (tp+fp);
double rec = (double)tp / (tp+fn);
double f1 = 2*pr*rec/(pr+rec);
this.tpTotal += tp;
this.fpTotal += fp;
this.fnTotal += fn;
return new double[]{pr, rec, f1};
}
示例3: copyWithNewLabels
import cc.mallet.cluster.Clustering; //导入方法依赖的package包/类
/**
* @param clustering
* @return A shallow copy of the argument where new objects are only
* allocated for the cluster assignment.
*/
public static Clustering copyWithNewLabels (Clustering clustering) {
int[] oldLabels = clustering.getLabels();
int[] newLabels = new int[oldLabels.length];
System.arraycopy(oldLabels, 0, newLabels, 0, oldLabels.length);
return new Clustering(clustering.getInstances(),
clustering.getNumClusters(),
newLabels);
}