📄 confusionmatrix.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.operator.performance;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.Example;/** A confusion matrix. * @version $Id: ConfusionMatrix.java,v 2.3 2003/04/15 19:49:47 fischer Exp $ */public class ConfusionMatrix extends MeasuredPerformance { private double threshold; private double thresholdLabel; private double[][] costMatrix; private double totalCost; private int exampleCount; /** If the (predicted) label exceeds the threshold is considered to be positive, otherwise negative. * If the classification is correct, the profit is increased by pp or nn, if the label is positive * and the predicted label is negative, the profit is increased by pn. In the opposite case the profit * is increased by np. */ public ConfusionMatrix(double threshold, double thresholdLabel, double pp, double pn, double np, double nn) { this.threshold = threshold; this.thresholdLabel = thresholdLabel; this.costMatrix = new double[2][2]; this.costMatrix[0][0] = pp; this.costMatrix[0][1] = pn; this.costMatrix[1][0] = np; this.costMatrix[1][1] = nn; } public String getName() { return "data mining performance"; } private ConfusionMatrix(ConfusionMatrix c) { this.threshold = c.threshold; this.thresholdLabel = c.thresholdLabel; this.costMatrix = new double[2][2]; this.costMatrix[0][0] = c.costMatrix[0][0]; this.costMatrix[0][1] = c.costMatrix[0][1]; this.costMatrix[1][0] = c.costMatrix[1][0]; this.costMatrix[1][1] = c.costMatrix[1][1]; } public void startCounting(ExampleSet set) { super.startCounting(set); totalCost = 0.0; } public double getFitness() { return getValue(); } public double getValue() { return totalCost / exampleCount; } public double getVariance() { return Double.NaN; } public void countExample(Example e) { int l = e.getLabel() >= thresholdLabel ? 0 : 1; int p = e.getPredictedLabel() >= threshold ? 0 : 1; totalCost += costMatrix[l][p]; exampleCount++; } public int compareTo(Object o) { double dif = ((ConfusionMatrix)o).getValue() - getValue(); if (dif < 0) return 1; if (dif > 0) return -1; return 0; } public Object clone() { return new ConfusionMatrix(this); } public double getThreshold() { return threshold; } public String toString() { return super.toString() + " (threshold="+threshold+")"; } public void buildAverage(PerformanceCriterion performance) { super.buildAverage(performance); ConfusionMatrix other = (ConfusionMatrix)performance; this.totalCost += other.totalCost; this.exampleCount += other.exampleCount; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -