label.java
来自「Boosting算法软件包」· Java 代码 · 共 49 行
JAVA
49 行
package jboost.examples;/** Holds the label of an example */public class Label extends MultiDiscreteAttribute { /** constructor @param value label's value */ public Label(int v) { super(v); } /** constructor @param values array of {0,1} boolean values indicating membership in each class */ public Label(boolean[] values) { super(values); } /** * Computes a loss for a predicted Label relative to this Label. * Specifically, the loss is 1 minus the number of classes at the * intersection of the two Label's, divided by the number of * classes in the predicted Label. (An exception occurs if no * classes in the predicted Label.) */ public double lossOfPrediction(Label p) { if (p.value >= 0) return (getMultiValue(p.value) ? 0.0 : 1.0); else { int num_plus = 0; int num_overlap = 0; for (int i = 0; i < p.values.length; i++) { if (p.values[i]) { num_plus++; if (getMultiValue(i)) num_overlap++; } } if (num_plus == 0) throw new IllegalArgumentException("label must have at " + "least one class in Label.lossOfPrediction"); return (num_plus - num_overlap) / ((double) num_plus); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?