Class LibLinearTrainer<T extends Output<T>>
java.lang.Object
org.tribuo.common.liblinear.LibLinearTrainer<T>
- All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable
,com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>
,Trainer<T>
- Direct Known Subclasses:
LibLinearClassificationTrainer
,LibLinearRegressionTrainer
A
Trainer
which wraps a liblinear-java trainer.
See:
Fan RE, Chang KW, Hsieh CJ, Wang XR, Lin CJ. "LIBLINEAR: A library for Large Linear Classification" Journal of Machine Learning Research, 2008.and for the original algorithm:
Cortes C, Vapnik V. "Support-Vector Networks" Machine Learning, 1995.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double
protected double
protected de.bwaldvogel.liblinear.Parameter
protected int
protected double
protected LibLinearType
<T> Fields inherited from interface org.tribuo.Trainer
DEFAULT_SEED
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
protected
LibLinearTrainer
(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion) Creates a trainer for a LibLinear modelprotected
LibLinearTrainer
(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon) Creates a trainer for a LibLinear model -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract LibLinearModel
<T> createModel
(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Construct the appropriate subtype of LibLinearModel for the prediction task.static <T extends Output<T>>
de.bwaldvogel.liblinear.FeatureNode[]exampleToNodes
(Example<T> example, ImmutableFeatureMap featureIDMap, List<de.bwaldvogel.liblinear.FeatureNode> features) Converts a TribuoExample
into a liblinearFeatureNode
array, including a bias feature.protected abstract com.oracle.labs.mlrg.olcut.util.Pair
<de.bwaldvogel.liblinear.FeatureNode[][], 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 de.bwaldvogel.liblinear.Parameter
setupParameters
(ImmutableOutputInfo<T> info) Constructs the parameters.toString()
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
<de.bwaldvogel.liblinear.Model> trainModels
(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs) Train all the liblinear instances necessary for this dataset.
-
Field Details
-
libLinearParams
-
trainerType
-
cost
-
maxIterations
-
terminationCriterion
@Config(description="Stop iterating when the loss score decreases by less than this value.") protected double terminationCriterion -
epsilon
@Config(description="Epsilon insensitivity in the regression cost function.") protected double epsilon
-
-
Constructor Details
-
LibLinearTrainer
protected LibLinearTrainer() -
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion) Creates a trainer for a LibLinear model- Parameters:
trainerType
- Loss function and optimisation method combination.cost
- Cost penalty for each incorrectly classified training point.maxIterations
- The maximum number of dataset iterations.terminationCriterion
- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).
-
LibLinearTrainer
protected LibLinearTrainer(LibLinearType<T> trainerType, double cost, int maxIterations, double terminationCriterion, double epsilon) Creates a trainer for a LibLinear model- Parameters:
trainerType
- Loss function and optimisation method combination.cost
- Cost penalty for each incorrectly classified training point.maxIterations
- The maximum number of dataset iterations.terminationCriterion
- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).epsilon
- The insensitivity of the regression loss to small differences.
-
-
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
-
train
-
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.
-
toString
-
trainModels
protected abstract List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] 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.
-
createModel
protected abstract LibLinearModel<T> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models) Construct the appropriate subtype of LibLinearModel for the prediction task.- Parameters:
provenance
- The model provenance.featureIDMap
- The feature id map.outputIDInfo
- The output id info.models
- The list of linear models.- Returns:
- An implementation of LibLinearModel.
-
extractData
protected abstract com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][], 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 parameters. 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 Parameters to use for training.
-
exampleToNodes
public static <T extends Output<T>> de.bwaldvogel.liblinear.FeatureNode[] exampleToNodes(Example<T> example, ImmutableFeatureMap featureIDMap, List<de.bwaldvogel.liblinear.FeatureNode> features) Converts a TribuoExample
into a liblinearFeatureNode
array, including a bias feature.If there is a collision between feature ids (i.e., if there is feature hashing or some other mechanism changing the feature ids) then the feature values are summed.
- Type Parameters:
T
- The output type.- Parameters:
example
- The input example.featureIDMap
- The feature id map which contains the example's indices.features
- A buffer. If null then an array list is created and used internally.- Returns:
- The features suitable for use in liblinear.
-
getProvenance
-