Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.mahout.classifier;
 public class ResultAnalyzer implements Summarizable {
   private ConfusionMatrix confusionMatrix = null;
    * === Summary ===
    * Correctly Classified Instances 635 92.9722 % Incorrectly Classified
    * Instances 48 7.0278 % Kappa statistic 0.923 Mean absolute error 0.0096 Root
    * mean squared error 0.0817 Relative absolute error 9.9344 % Root relative
    * squared error 37.2742 % Total Number of Instances 683
   private int correctlyClassified = 0;
   private int incorrectlyClassified = 0;
   public ResultAnalyzer(Collection<StringlabelSetString defaultLabel) {
      = new ConfusionMatrix(labelSetdefaultLabel);
     return this.;


correctLabel The correct label
classifiedResult The classified result
whether the instance was correct or not
   public boolean addInstance(String correctLabelClassifierResult classifiedResult) {
     boolean result = correctLabel.equals(classifiedResult.getLabel());
     if (result) {
     } else {
     return result;
   public String toString() {
     return "";
   public String summarize() {
     StringBuilder returnString = new StringBuilder();
     int totalClassified =  + ;
     double percentageCorrect = (double) 100 * 
         / (totalClassified);
     double percentageIncorrect = (double) 100 * 
         / (totalClassified);
     DecimalFormat decimalFormatter = new DecimalFormat("0.####");
     returnString.append(StringUtils.rightPad("Correctly Classified Instances",
         40)).append(": ").append(StringUtils.leftPad(Integer.toString(), 10))
         .append('\t').append(StringUtils.leftPad(decimalFormatter.format(percentageCorrect), 10)).append("%\n");
         "Incorrectly Classified Instances", 40)).append(": ").append(StringUtils
         .leftPad(Integer.toString(), 10)).append('\t')
         .append(StringUtils.leftPad(decimalFormatter.format(percentageIncorrect), 10)).append("%\n");
     returnString.append(StringUtils.rightPad("Total Classified Instances", 40)).append(": ")
         .append(StringUtils.leftPad(Integer.toString(totalClassified), 10)).append('\n');
    return returnString.toString();
New to GrepCode? Check out our FAQ X