source: src/main/java/weka/classifiers/misc/monotone/ZeroOneLossFunction.java @ 7

Last change on this file since 7 was 4, checked in by gnappo, 14 years ago

Import di weka.

File size: 2.1 KB
Line 
1/*
2 *    This program is free software; you can redistribute it and/or modify
3 *    it under the terms of the GNU General Public License as published by
4 *    the Free Software Foundation; either version 2 of the License, or
5 *    (at your option) any later version.
6 *
7 *    This program is distributed in the hope that it will be useful,
8 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 *    GNU General Public License for more details.
11 *
12 *    You should have received a copy of the GNU General Public License
13 *    along with this program; if not, write to the Free Software
14 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 */
16
17/*
18 *    ZeroOneLossFunction.java
19 *    Copyright (C) 2004 Stijn Lievens
20 *
21 */
22
23package weka.classifiers.misc.monotone;
24
25import weka.core.RevisionHandler;
26import weka.core.RevisionUtils;
27
28/**
29 * Class implementing the zero-one loss function, this is
30 * an incorrect prediction always accounts for one unit loss.
31 *
32 * <p>
33 * This implementation is done as part of the master's thesis: "Studie
34 * en implementatie van instantie-gebaseerde algoritmen voor gesuperviseerd
35 * rangschikken", Stijn Lievens, Ghent University, 2004.
36 * </p>
37 *
38 * @author Stijn Lievens (stijn.lievens@ugent.be)
39 * @version $Revision: 5922 $
40 */
41public class ZeroOneLossFunction
42  implements NominalLossFunction, RevisionHandler {
43
44  /**
45   * Returns the zero-one loss function between two class values.
46   *
47   * @param actual the actual class value
48   * @param predicted the predicted class value
49   * @return 1 if the actual and predicted value differ, 0 otherwise
50   */
51  public final double loss(double actual, double predicted) {
52    return actual == predicted ? 0 : 1;
53  }
54
55  /**
56   * Returns a string with the name of the loss function.
57   *
58   * @return a string with the name of the loss function
59   */
60  public String toString() {
61    return "ZeroOneLossFunction";
62  }
63 
64  /**
65   * Returns the revision string.
66   *
67   * @return            the revision
68   */
69  public String getRevision() {
70    return RevisionUtils.extract("$Revision: 5922 $");
71  }
72}
Note: See TracBrowser for help on using the repository browser.