public class LibSVMClassificationTrainer extends LibSVMTrainer<Label> implements WeightedLabels
Note the train method is synchronized on LibSVMTrainer.class
due to a global RNG in LibSVM.
This is insufficient to ensure reproducibility if LibSVM is used directly in the same JVM as Tribuo, but
avoids locking on classes Tribuo does not control.
See:
Chang CC, Lin CJ. "LIBSVM: a library for Support Vector Machines" ACM transactions on intelligent systems and technology (TIST), 2011.for the nu-svc algorithm:
Schölkopf B, Smola A, Williamson R, Bartlett P L. "New support vector algorithms" Neural Computation, 2000, 1207-1245.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
parameters, svmType
DEFAULT_SEED
Modifier | Constructor and Description |
---|---|
protected |
LibSVMClassificationTrainer()
For OLCUT.
|
|
LibSVMClassificationTrainer(SVMParameters<Label> parameters)
Constructs a classification LibSVM trainer using the specified parameters
and
Trainer.DEFAULT_SEED . |
|
LibSVMClassificationTrainer(SVMParameters<Label> parameters,
long seed)
Constructs a classification LibSVM trainer using the specified parameters and seed.
|
Modifier and Type | Method and Description |
---|---|
protected LibSVMModel<Label> |
createModel(ModelProvenance provenance,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<Label> outputIDInfo,
List<libsvm.svm_model> models)
Construct the appropriate subtype of LibSVMModel for the prediction task.
|
protected com.oracle.labs.mlrg.olcut.util.Pair<libsvm.svm_node[][],double[][]> |
extractData(Dataset<Label> data,
ImmutableOutputInfo<Label> outputInfo,
ImmutableFeatureMap featureMap)
Extracts the features and
Output s in LibSVM's format. |
void |
postConfig()
Used by the OLCUT configuration system, and should not be called by external code.
|
void |
setLabelWeights(Map<Label,Float> weights)
Sets the label weights used by this trainer.
|
protected libsvm.svm_parameter |
setupParameters(ImmutableOutputInfo<Label> outputIDInfo)
Constructs the svm_parameter.
|
protected List<libsvm.svm_model> |
trainModels(libsvm.svm_parameter curParams,
int numFeatures,
libsvm.svm_node[][] features,
double[][] outputs,
SplittableRandom localRNG)
Train all the LibSVM instances necessary for this dataset.
|
exampleToNodes, getInvocationCount, getProvenance, toString, train, train
protected LibSVMClassificationTrainer()
public LibSVMClassificationTrainer(SVMParameters<Label> parameters)
Trainer.DEFAULT_SEED
.parameters
- The SVM parameters.public LibSVMClassificationTrainer(SVMParameters<Label> parameters, long seed)
parameters
- The SVM parameters.seed
- The RNG seed for LibSVM's internal RNG.public void postConfig()
postConfig
in interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfig
in class LibSVMTrainer<Label>
protected LibSVMModel<Label> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Label> outputIDInfo, List<libsvm.svm_model> models)
LibSVMTrainer
createModel
in class LibSVMTrainer<Label>
provenance
- The model provenance.featureIDMap
- The feature id map.outputIDInfo
- The output id info.models
- The svm models.protected List<libsvm.svm_model> trainModels(libsvm.svm_parameter curParams, int numFeatures, libsvm.svm_node[][] features, double[][] outputs, SplittableRandom localRNG)
LibSVMTrainer
trainModels
in class LibSVMTrainer<Label>
curParams
- The LibSVM parameters.numFeatures
- The number of features in this dataset.features
- The features themselves.outputs
- The outputs.localRNG
- The RNG to use for seeding LibSVM's RNG.protected com.oracle.labs.mlrg.olcut.util.Pair<libsvm.svm_node[][],double[][]> extractData(Dataset<Label> data, ImmutableOutputInfo<Label> outputInfo, ImmutableFeatureMap featureMap)
LibSVMTrainer
Output
s in LibSVM's format.extractData
in class LibSVMTrainer<Label>
data
- The input data.outputInfo
- The output info.featureMap
- The feature info.protected libsvm.svm_parameter setupParameters(ImmutableOutputInfo<Label> outputIDInfo)
LibSVMTrainer
setupParameters
in class LibSVMTrainer<Label>
outputIDInfo
- The output info.public void setLabelWeights(Map<Label,Float> weights)
WeightedLabels
Supply Collections.emptyMap()
to turn off label weights.
setLabelWeights
in interface WeightedLabels
weights
- A map from Label instances to weight values.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.