Java List Create createConfusionMatrix(HashMap> tempM, List actualLabelsList, List predictedLabelsList)

Here you can find the source of createConfusionMatrix(HashMap> tempM, List actualLabelsList, List predictedLabelsList)

Description

Creates a confusion matrix by collecting the results from the overall CV run stored in tempM

License

Apache License

Parameter

Parameter Description
tempM a parameter
actualLabelsList the label powerset transformed list of actual/true labels
predictedLabelsList the label powerset transformed list of predicted labels

Declaration

public static double[][] createConfusionMatrix(HashMap<String, Map<String, Integer>> tempM,
        List<String> actualLabelsList, List<String> predictedLabelsList) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2015//  www.  jav a 2 s  .c o m
 * Ubiquitous Knowledge Processing (UKP) Lab
 * Technische Universit?t Darmstadt
 * 
 * Licensed 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.
 ******************************************************************************/

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;
import java.util.Map;

public class Main {
    /**
     * Creates a confusion matrix by collecting the results from the overall CV run stored in
     * {@code tempM}
     * 
     * @param tempM
     * @param actualLabelsList
     *            the label powerset transformed list of actual/true labels
     * @param predictedLabelsList
     *            the label powerset transformed list of predicted labels
     * @return
     */
    public static double[][] createConfusionMatrix(HashMap<String, Map<String, Integer>> tempM,
            List<String> actualLabelsList, List<String> predictedLabelsList) {
        double[][] matrix = new double[actualLabelsList.size()][predictedLabelsList.size()];

        Iterator<String> actualsIter = tempM.keySet().iterator();
        while (actualsIter.hasNext()) {
            String actual = actualsIter.next();
            Iterator<String> predsIter = tempM.get(actual).keySet().iterator();
            while (predsIter.hasNext()) {
                String pred = predsIter.next();
                int a = actualLabelsList.indexOf(actual);
                int p = predictedLabelsList.indexOf(pred);
                matrix[a][p] = tempM.get(actual).get(pred);
            }
        }
        return matrix;
    }
}

Related

  1. createClassList(List objects)
  2. createColumnsToken(List columnnames)
  3. createCommaList(List values, int rowCharacterCount)
  4. createCommand(LinkedList> list)
  5. createConflictMessage(List conflicts)
  6. createConsultInfoMap(List resAry)
  7. createCSVLine(final char textQ, final char fieldD, final List values)
  8. createDefaultGroup(String name, String prefabGroup, List nodes)
  9. createDefaultValueList(int capacity, T defaultValue)

  10. HOME | Copyright © www.java2s.com 2016