Class LibLinearModel<T extends Output<T>>

All Implemented Interfaces:<ModelProvenance>, Serializable
Direct Known Subclasses:
LibLinearAnomalyModel, LibLinearClassificationModel, LibLinearRegressionModel

public abstract class LibLinearModel<T extends Output<T>> extends Model<T>
A Model which wraps a LibLinear-java model.

It disables the LibLinear debug output as it's very chatty.


 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.
See Also:
  • Field Details

    • models

      protected List<de.bwaldvogel.liblinear.Model> models
      The list of LibLinear models. Multiple models are used by multi-label and multidimensional regression outputs.

      Not final to support deserialization reordering of multidimensional regression models which have an incorrect id mapping. Will be final again in some future version which doesn't maintain serialization compatibility with 4.X.

  • Constructor Details

    • LibLinearModel

      protected LibLinearModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> labelIDMap, boolean generatesProbabilities, List<de.bwaldvogel.liblinear.Model> models)
      Constructs a LibLinear model from the supplied arguments.
      name - The model name.
      description - The model provenance.
      featureIDMap - The features this model knows about.
      labelIDMap - The outputs this model produces.
      generatesProbabilities - Does this model generate probabilities?
      models - The liblinear models themselves.
  • Method Details

    • getInnerModels

      public List<de.bwaldvogel.liblinear.Model> getInnerModels()
      Returns an unmodifiable list containing a copy of each model.

      As liblinear-java models don't expose a copy constructor this requires serializing each model to a String and rebuilding it, and is thus quite expensive.

      A copy of all of the models.
    • getExcuse

      public Optional<Excuse<T>> getExcuse(Example<T> e)
      This call is expensive as it copies out the weight matrix from the LibLinear model.

      Prefer getExcuses(java.lang.Iterable<org.tribuo.Example<T>>) to get multiple excuses.

      Specified by:
      getExcuse in class Model<T extends Output<T>>
      e - The example to excuse.
      An Excuse for this example.
    • getExcuses

      public Optional<List<Excuse<T>>> getExcuses(Iterable<Example<T>> examples)
      Description copied from class: Model
      Generates an excuse for each example.

      This may be an expensive operation, and probably should be overridden in subclasses for performance reasons.

      These excuses either contain per class information or an entry with key Model.ALL_OUTPUTS.

      The optional is empty if the model does not provide excuses.

      getExcuses in class Model<T extends Output<T>>
      examples - An iterable of examples
      A optional list of excuses. The Optional is empty if this model does not provide excuses.
    • copyModel

      protected static de.bwaldvogel.liblinear.Model copyModel(de.bwaldvogel.liblinear.Model model)
      Copies the model by writing it out to a String and loading it back in.

      Unfortunately liblinear-java doesn't have a copy constructor on it's model.

      model - The model to copy.
      A deep copy of the model.
    • getFeatureWeights

      protected abstract double[][] getFeatureWeights()
      Extracts the feature weights from the models. The first dimension corresponds to the model index.
      The feature weights.
    • innerGetExcuse

      protected abstract Excuse<T> innerGetExcuse(Example<T> e, double[][] featureWeights)
      The call to getFeatureWeights in the public methods copies the weights array so this inner method exists to save the copy in getExcuses.

      If it becomes a problem then we could cache the feature weights in the model.

      e - The example.
      featureWeights - The per dimension feature weights.
      An excuse for this example.