Class LibSVMTrainer<T extends Output<T>>
java.lang.Object
org.tribuo.common.libsvm.LibSVMTrainer<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>
,Trainer<T>
- Direct Known Subclasses:
LibSVMAnomalyTrainer
,LibSVMClassificationTrainer
,LibSVMRegressionTrainer
A trainer that will train using libsvm's Java implementation.
See:
Chang CC, Lin CJ. "LIBSVM: a library for Support Vector Machines" ACM transactions on intelligent systems and technology (TIST), 2011.for the nu-svm 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected libsvm.svm_parameter
The SVM parameters suitable for use by LibSVM.The type of SVM algorithm.Fields inherited from interface org.tribuo.Trainer
DEFAULT_SEED
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
For olcut.protected
LibSVMTrainer
(SVMParameters<T> parameters) Constructs a LibSVMTrainer from the parameters. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract LibSVMModel
<T> createModel
(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<libsvm.svm_model> models) Construct the appropriate subtype of LibSVMModel for the prediction task.static <T extends Output<T>>
libsvm.svm_node[]exampleToNodes
(Example<T> example, ImmutableFeatureMap featureIDMap, List<libsvm.svm_node> features) Convert the example into an array of svm_node which represents a sparse feature vector.protected abstract com.oracle.labs.mlrg.olcut.util.Pair
<libsvm.svm_node[][], double[][]> extractData
(Dataset<T> data, ImmutableOutputInfo<T> outputInfo, ImmutableFeatureMap featureMap) Extracts the features andOutput
s in LibLinear's format.int
The number of times this trainer instance has had it's train method invoked.void
Used by the OLCUT configuration system, and should not be called by external code.protected libsvm.svm_parameter
setupParameters
(ImmutableOutputInfo<T> info) Constructs the svm_parameter.toString()
Trains a predictive model using the examples in the given data set.train
(Dataset<T> examples, Map<String, com.oracle.labs.mlrg.olcut.provenance.Provenance> runProvenance) Trains a predictive model using the examples in the given data set.protected abstract List
<libsvm.svm_model> trainModels
(libsvm.svm_parameter curParams, int numFeatures, libsvm.svm_node[][] features, double[][] outputs) Train all the liblinear instances necessary for this dataset.
-
Field Details
-
parameters
The SVM parameters suitable for use by LibSVM. -
svmType
-
-
Constructor Details
-
LibSVMTrainer
protected LibSVMTrainer()For olcut. -
LibSVMTrainer
Constructs a LibSVMTrainer from the parameters.- Parameters:
parameters
- The SVM parameters.
-
-
Method Details
-
postConfig
Used by the OLCUT configuration system, and should not be called by external code.- Specified by:
postConfig
in interfacecom.oracle.labs.mlrg.olcut.config.Configurable
-
toString
-
train
Description copied from interface:Trainer
Trains a predictive model using the examples in the given data set. -
train
-
createModel
protected abstract LibSVMModel<T> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<libsvm.svm_model> models) Construct the appropriate subtype of LibSVMModel for the prediction task.- Parameters:
provenance
- The model provenance.featureIDMap
- The feature id map.outputIDInfo
- The output id info.models
- The svm models.- Returns:
- An implementation of LibSVMModel.
-
trainModels
protected abstract List<libsvm.svm_model> trainModels(libsvm.svm_parameter curParams, int numFeatures, libsvm.svm_node[][] features, double[][] outputs) Train all the liblinear instances necessary for this dataset.- Parameters:
curParams
- The LibLinear parameters.numFeatures
- The number of features in this dataset.features
- The features themselves.outputs
- The outputs.- Returns:
- A list of liblinear models.
-
extractData
protected abstract com.oracle.labs.mlrg.olcut.util.Pair<libsvm.svm_node[][], double[][]> extractData(Dataset<T> data, ImmutableOutputInfo<T> outputInfo, ImmutableFeatureMap featureMap) Extracts the features andOutput
s in LibLinear's format.- Parameters:
data
- The input data.outputInfo
- The output info.featureMap
- The feature info.- Returns:
- The features and outputs.
-
setupParameters
Constructs the svm_parameter. Most of the time this is a no-op, but classification overrides it to incorporate label weights if they exist.- Parameters:
info
- The output info.- Returns:
- The svm_parameters to use for training.
-
getInvocationCount
Description copied from interface:Trainer
The number of times this trainer instance has had it's train method invoked.This is used to determine how many times the trainer's RNG has been accessed to ensure replicability in the random number stream.
- Specified by:
getInvocationCount
in interfaceTrainer<T extends Output<T>>
- Returns:
- The number of train invocations.
-
exampleToNodes
public static <T extends Output<T>> libsvm.svm_node[] exampleToNodes(Example<T> example, ImmutableFeatureMap featureIDMap, List<libsvm.svm_node> features) Convert the example into an array of svm_node which represents a sparse feature vector.If there are collisions in the feature ids then the values are summed.
- Type Parameters:
T
- The type of the ouput.- Parameters:
example
- The example to convert.featureIDMap
- The feature id map which holds the indices.features
- A buffer to use.- Returns:
- A sparse feature vector.
-
getProvenance
-