public class OneVersusRest<T> extends java.lang.Object implements SoftClassifier<T>
Making decisions means applying all classifiers to an unseen sample x and predicting the label k for which the corresponding classifier reports the highest confidence score.
Although this strategy is popular, it is a heuristic that suffers from several problems. Firstly, the scale of the confidence values may differ between the binary classifiers. Second, even if the class distribution is balanced in the training set, the binary classification learners see unbalanced distributions because typically the set of negatives they see is much larger than the set of positives.
Constructor and Description |
---|
OneVersusRest(Classifier<T>[] classifiers,
PlattScaling[] platts)
Constructor.
|
OneVersusRest(Classifier<T>[] classifiers,
PlattScaling[] platts,
smile.util.IntSet labels)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static <T> OneVersusRest<T> |
fit(T[] x,
int[] y,
java.util.function.BiFunction<T[],int[],Classifier<T>> trainer)
Fits a multi-class model with binary classifiers.
|
static <T> OneVersusRest<T> |
fit(T[] x,
int[] y,
int pos,
int neg,
java.util.function.BiFunction<T[],int[],Classifier<T>> trainer)
Fits a multi-class model with binary classifiers.
|
int |
predict(T x)
Predicts the class label of an instance.
|
int |
predict(T x,
double[] posteriori)
Predicts the class label of an instance and also calculate a posteriori
probabilities.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
applyAsDouble, applyAsInt, f, predict
public OneVersusRest(Classifier<T>[] classifiers, PlattScaling[] platts)
classifiers
- the binary classifier for each one-vs-rest case.public OneVersusRest(Classifier<T>[] classifiers, PlattScaling[] platts, smile.util.IntSet labels)
classifiers
- the binary classifier for each one-vs-rest case.labels
- the class labels.public static <T> OneVersusRest<T> fit(T[] x, int[] y, java.util.function.BiFunction<T[],int[],Classifier<T>> trainer)
x
- the training samples.y
- the training labels.trainer
- the lambda to train binary classifiers.public static <T> OneVersusRest<T> fit(T[] x, int[] y, int pos, int neg, java.util.function.BiFunction<T[],int[],Classifier<T>> trainer)
x
- the training samples.y
- the training labels.pos
- the class label for one case.neg
- the class label for rest cases.trainer
- the lambda to train binary classifiers.public int predict(T x)
Classifier
predict
in interface Classifier<T>
x
- the instance to be classified.public int predict(T x, double[] posteriori)
SoftClassifier
predict
in interface SoftClassifier<T>
x
- an instance to be classified.posteriori
- the array to store a posteriori probabilities on output.