Here you can find the source of createConfusionMatrix(HashMap
Parameter | Description |
---|---|
tempM | a parameter |
actualLabelsList | the label powerset transformed list of actual/true labels |
predictedLabelsList | the label powerset transformed list of predicted labels |
public static double[][] createConfusionMatrix(HashMap<String, Map<String, Integer>> tempM, List<String> actualLabelsList, List<String> predictedLabelsList)
//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; } }