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 http://www.apache.org/licenses/LICENSE-2.0 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.df.callback;
 
 
Collects a forest's predictions
 
 public class ForestPredictions implements PredictionCallback {

  
predictions[n][label] = number of times instance n was classified 'label'
 
   private final int[][] predictions;
 
   public ForestPredictions(int nbInstancesint nblabels) {
      = new int[nbInstances][];
     for (int index = 0; index < .index++) {
       [index] = new int[nblabels];
     }
   }
 
   @Override
   public void prediction(int treeIdint instanceIdint prediction) {
     if (prediction != -1)
       [instanceId][prediction]++;
   }
 
   @Override
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
     if (obj == null || !(obj instanceof ForestPredictions))
       return false;
 
     ForestPredictions fp = (ForestPredictionsobj;
 
     if (. != fp.predictions.length) {
       return false;
     }
 
     for (int i = 0; i < .i++) {
       if (!Arrays.equals([i], fp.predictions[i])) {
         return false;
       }
     }
 
     return true;
   }
 
   @Override
   public int hashCode() {
     int hashCode = 1;
     for (int[] row : ) {
       for (int value : row) {
         hashCode = 31 * hashCode + value;
       }
     }
     return hashCode;
   }

  
compute the prediction for each instance. the prediction of an instance is the index of the label that got most of the votes

Parameters:
rng
Returns:
 
   public int[] computePredictions(Random rng) {
     int[] result = new int[.];
     Arrays.fill(result, -1);
 
     for (int index = 0; index < .index++) {
       if (DataUtils.sum([index]) == 0)
         continue// this instance has not been classified
 
       result[index] = DataUtils.maxindex(rng[index]);
     }
 
     return result;
   }
 
New to GrepCode? Check out our FAQ X