public class LibLinearClassificationTrainer extends LibLinearTrainer<Label> implements WeightedLabels
Trainer
which wraps a liblinear-java classifier trainer.
Note the train method is synchronized on LibLinearTrainer.class
due to a global RNG in liblinear-java.
This is insufficient to ensure reproducibility if liblinear-java is used directly in the same JVM as Tribuo, but
avoids locking on classes Tribuo does not control.
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.
cost, epsilon, libLinearParams, maxIterations, terminationCriterion, trainerType
DEFAULT_SEED
Constructor and Description |
---|
LibLinearClassificationTrainer()
Creates a trainer using the default values (L2R_L2LOSS_SVC_DUAL, 1, 0.1).
|
LibLinearClassificationTrainer(LinearClassificationType trainerType,
double cost,
double terminationCriterion)
Creates a trainer for a LibLinearClassificationModel.
|
LibLinearClassificationTrainer(LinearClassificationType trainerType,
double cost,
int maxIterations,
double terminationCriterion)
Creates a trainer for a LibLinear model
|
Modifier and Type | Method and Description |
---|---|
protected LibLinearModel<Label> |
createModel(ModelProvenance provenance,
ImmutableFeatureMap featureIDMap,
ImmutableOutputInfo<Label> outputIDInfo,
List<de.bwaldvogel.liblinear.Model> models)
Construct the appropriate subtype of LibLinearModel for the prediction task.
|
protected com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][],double[][]> |
extractData(Dataset<Label> data,
ImmutableOutputInfo<Label> outputInfo,
ImmutableFeatureMap featureMap)
Extracts the features and
Output s in LibLinear'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 de.bwaldvogel.liblinear.Parameter |
setupParameters(ImmutableOutputInfo<Label> labelIDMap)
Constructs the parameters.
|
protected 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.
|
exampleToNodes, getInvocationCount, getProvenance, toString, train, train
public LibLinearClassificationTrainer()
public LibLinearClassificationTrainer(LinearClassificationType trainerType, double cost, double terminationCriterion)
trainerType
- Loss function and optimisation method combination.cost
- Cost penalty for each incorrectly classified training point.terminationCriterion
- How close does the optimisation function need to be before terminating that subproblem (usually set to 0.1).public LibLinearClassificationTrainer(LinearClassificationType trainerType, double cost, int maxIterations, double terminationCriterion)
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).public void postConfig()
postConfig
in interface com.oracle.labs.mlrg.olcut.config.Configurable
postConfig
in class LibLinearTrainer<Label>
protected List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs)
LibLinearTrainer
trainModels
in class LibLinearTrainer<Label>
curParams
- The LibLinear parameters.numFeatures
- The number of features in this dataset.features
- The features themselves.outputs
- The outputs.protected LibLinearModel<Label> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Label> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models)
LibLinearTrainer
createModel
in class LibLinearTrainer<Label>
provenance
- The model provenance.featureIDMap
- The feature id map.outputIDInfo
- The output id info.models
- The list of linear models.protected com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][],double[][]> extractData(Dataset<Label> data, ImmutableOutputInfo<Label> outputInfo, ImmutableFeatureMap featureMap)
LibLinearTrainer
Output
s in LibLinear's format.extractData
in class LibLinearTrainer<Label>
data
- The input data.outputInfo
- The output info.featureMap
- The feature info.protected de.bwaldvogel.liblinear.Parameter setupParameters(ImmutableOutputInfo<Label> labelIDMap)
LibLinearTrainer
setupParameters
in class LibLinearTrainer<Label>
labelIDMap
- 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.