Package smile.classification
Class OneVersusOne<T>
java.lang.Object
smile.classification.AbstractClassifier<T>
smile.classification.OneVersusOne<T>
- Type Parameters:
T
- the data type of model input objects.
- All Implemented Interfaces:
Serializable
,ToDoubleFunction<T>
,ToIntFunction<T>
,Classifier<T>
One-vs-one strategy for reducing the problem of
multiclass classification to multiple binary classification problems.
This approach trains
K (K − 1) / 2
binary classifiers for a
K-way multiclass problem; each receives the samples of a pair of
classes from the original training set, and must learn to distinguish
these two classes. At prediction time, a voting scheme is applied:
all K (K − 1) / 2
classifiers are applied to an unseen
sample and the class that got the highest number of positive predictions
gets predicted by the combined classifier. Like One-vs-rest, one-vs-one
suffers from ambiguities in that some regions of its input space may
receive the same number of votes.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface smile.classification.Classifier
Classifier.Trainer<T,
M extends Classifier<T>> -
Field Summary
Fields inherited from class smile.classification.AbstractClassifier
classes
-
Constructor Summary
ConstructorDescriptionOneVersusOne
(Classifier<T>[][] classifiers, PlattScaling[][] platt) Constructor.OneVersusOne
(Classifier<T>[][] classifiers, PlattScaling[][] platt, IntSet labels) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataFrameClassifier
fit
(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer) Fits a multi-class model with binary data frame classifiers.static <T> OneVersusOne
<T> fit
(T[] x, int[] y, int pos, int neg, BiFunction<T[], int[], Classifier<T>> trainer) Fits a multi-class model with binary classifiers.static <T> OneVersusOne
<T> fit
(T[] x, int[] y, BiFunction<T[], int[], Classifier<T>> trainer) Fits a multi-class model with binary classifiers.int
Prediction is based on voting.int
Prediction is based posteriori probability estimation.boolean
soft()
Returns true if this is a soft classifier that can estimate the posteriori probabilities of classification.Methods inherited from class smile.classification.AbstractClassifier
classes, numClasses
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface smile.classification.Classifier
applyAsDouble, applyAsInt, online, predict, predict, predict, predict, predict, predict, score, update, update, update
-
Constructor Details
-
OneVersusOne
Constructor.- Parameters:
classifiers
- the binary classifier for each one-vs-one case. Only the lower half is needed.platt
- Platt scaling models.
-
OneVersusOne
Constructor.- Parameters:
classifiers
- the binary classifier for each one-vs-one case. Only the lower half is needed.platt
- Platt scaling models.labels
- the class label encoder.
-
-
Method Details
-
fit
Fits a multi-class model with binary classifiers. Use +1 and -1 as positive and negative class labels.- Type Parameters:
T
- the data type.- Parameters:
x
- the training samples.y
- the training labels.trainer
- the lambda to train binary classifiers.- Returns:
- the model.
-
fit
public static <T> OneVersusOne<T> fit(T[] x, int[] y, int pos, int neg, BiFunction<T[], int[], Classifier<T>> trainer) Fits a multi-class model with binary classifiers.- Type Parameters:
T
- the data type.- Parameters:
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.- Returns:
- the model.
-
fit
public static DataFrameClassifier fit(Formula formula, DataFrame data, BiFunction<Formula, DataFrame, DataFrameClassifier> trainer) Fits a multi-class model with binary data frame classifiers.- Parameters:
formula
- a symbolic description of the model to be fitted.data
- the data frame of the explanatory and response variables.trainer
- the lambda to train binary classifiers.- Returns:
- the model.
-
predict
Prediction is based on voting.- Parameters:
x
- the instance to be classified.- Returns:
- the predicted class label.
-
soft
public boolean soft()Description copied from interface:Classifier
Returns true if this is a soft classifier that can estimate the posteriori probabilities of classification.- Returns:
- true if soft classifier.
-
predict
Prediction is based posteriori probability estimation. The result may be different from predict(T x).- Parameters:
x
- an instance to be classified.posteriori
- a posteriori probabilities on output.- Returns:
- the predicted class label
-