Class LibLinearClassificationTrainer

java.lang.Object
org.tribuo.common.liblinear.LibLinearTrainer<Label>
org.tribuo.classification.liblinear.LibLinearClassificationTrainer
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable, com.oracle.labs.mlrg.olcut.provenance.Provenancable<TrainerProvenance>, WeightedLabels, Trainer<Label>

public class LibLinearClassificationTrainer extends LibLinearTrainer<Label> implements WeightedLabels
A 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.
 
  • Constructor Details

    • LibLinearClassificationTrainer

      public LibLinearClassificationTrainer()
      Creates a trainer using the default values (L2R_L2LOSS_SVC_DUAL, 1, 0.1).
    • LibLinearClassificationTrainer

      public LibLinearClassificationTrainer(LinearClassificationType trainerType, double cost, double terminationCriterion)
      Creates a trainer for a LibLinearClassificationModel. Sets maxIterations to 1000.
      Parameters:
      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).
    • LibLinearClassificationTrainer

      public LibLinearClassificationTrainer(LinearClassificationType 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).
  • Method Details

    • postConfig

      public void postConfig()
      Used by the OLCUT configuration system, and should not be called by external code.
      Specified by:
      postConfig in interface com.oracle.labs.mlrg.olcut.config.Configurable
      Overrides:
      postConfig in class LibLinearTrainer<Label>
    • trainModels

      protected List<de.bwaldvogel.liblinear.Model> trainModels(de.bwaldvogel.liblinear.Parameter curParams, int numFeatures, de.bwaldvogel.liblinear.FeatureNode[][] features, double[][] outputs)
      Description copied from class: LibLinearTrainer
      Train all the liblinear instances necessary for this dataset.
      Specified by:
      trainModels in class LibLinearTrainer<Label>
      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 LibLinearModel<Label> createModel(ModelProvenance provenance, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<Label> outputIDInfo, List<de.bwaldvogel.liblinear.Model> models)
      Description copied from class: LibLinearTrainer
      Construct the appropriate subtype of LibLinearModel for the prediction task.
      Specified by:
      createModel in class LibLinearTrainer<Label>
      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 com.oracle.labs.mlrg.olcut.util.Pair<de.bwaldvogel.liblinear.FeatureNode[][],double[][]> extractData(Dataset<Label> data, ImmutableOutputInfo<Label> outputInfo, ImmutableFeatureMap featureMap)
      Description copied from class: LibLinearTrainer
      Extracts the features and Outputs in LibLinear's format.
      Specified by:
      extractData in class LibLinearTrainer<Label>
      Parameters:
      data - The input data.
      outputInfo - The output info.
      featureMap - The feature info.
      Returns:
      The features and outputs.
    • setupParameters

      protected de.bwaldvogel.liblinear.Parameter setupParameters(ImmutableOutputInfo<Label> labelIDMap)
      Description copied from class: LibLinearTrainer
      Constructs the parameters. Most of the time this is a no-op, but classification overrides it to incorporate label weights if they exist.
      Overrides:
      setupParameters in class LibLinearTrainer<Label>
      Parameters:
      labelIDMap - The output info.
      Returns:
      The Parameters to use for training.
    • setLabelWeights

      public void setLabelWeights(Map<Label,Float> weights)
      Description copied from interface: WeightedLabels
      Sets the label weights used by this trainer.

      Supply Collections.emptyMap() to turn off label weights.

      Specified by:
      setLabelWeights in interface WeightedLabels
      Parameters:
      weights - A map from Label instances to weight values.