Class LibSVMModel<T extends Output<T>>

java.lang.Object
org.tribuo.Model<T>
org.tribuo.common.libsvm.LibSVMModel<T>
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<ModelProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.ModelProto>
Direct Known Subclasses:
LibSVMAnomalyModel, LibSVMClassificationModel, LibSVMRegressionModel

public abstract class LibSVMModel<T extends Output<T>> extends Model<T> implements Serializable
A model that uses an underlying libSVM model to make the predictions.

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

    • models

      protected List<libsvm.svm_model> models
      The LibSVM models. Multiple models are used for multi-label or 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

    • LibSVMModel

      protected LibSVMModel(String name, ModelProvenance description, ImmutableFeatureMap featureIDMap, ImmutableOutputInfo<T> outputIDInfo, boolean generatesProbabilities, List<libsvm.svm_model> models)
      Constructs a LibSVMModel from the supplied arguments.
      Parameters:
      name - The model name.
      description - The model provenance.
      featureIDMap - The features the model knows about.
      outputIDInfo - The outputs the model can produce.
      generatesProbabilities - Does the model generate probabilities or not?
      models - The svm models themselves.
  • Method Details

    • getModel

      @Deprecated public List<libsvm.svm_model> getModel()
      Deprecated.
      Deprecated to unify the names across LibLinear, LibSVM and XGBoost.
      Returns an unmodifiable copy of the underlying list of libsvm models.
      Returns:
      The underlying model list.
    • getInnerModels

      public List<libsvm.svm_model> getInnerModels()
      Returns an unmodifiable copy of the underlying list of libsvm models.
      Returns:
      The underlying model list.
    • getTopFeatures

      public Map<String,List<com.oracle.labs.mlrg.olcut.util.Pair<String,Double>>> getTopFeatures(int n)
      Description copied from class: Model
      Gets the top n features associated with this model.

      If the model does not produce per output feature lists, it returns a map with a single element with key Model.ALL_OUTPUTS.

      If the model cannot describe it's top features then it returns Collections.emptyMap().

      Specified by:
      getTopFeatures in class Model<T extends Output<T>>
      Parameters:
      n - the number of features to return. If this value is less than 0, all features should be returned for each class, unless the model cannot score it's features.
      Returns:
      a map from string outputs to an ordered list of pairs of feature names and weights associated with that feature in the model
    • getExcuse

      public Optional<Excuse<T>> getExcuse(Example<T> example)
      Description copied from class: Model
      Generates an excuse for an example.

      This attempts to explain a classification result. Generating an excuse may be quite an expensive operation.

      This excuse either contains per class information or an entry with key Model.ALL_OUTPUTS.

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

      Specified by:
      getExcuse in class Model<T extends Output<T>>
      Parameters:
      example - The input example.
      Returns:
      An optional excuse object. The optional is empty if this model does not provide excuses.
    • copyModel

      protected static libsvm.svm_model copyModel(libsvm.svm_model model)
      Copies an svm_model, as it does not provide a copy method.
      Parameters:
      model - The svm_model to copy.
      Returns:
      A deep copy of the model.
    • modelEquals

      public static boolean modelEquals(libsvm.svm_model first, libsvm.svm_model second)
      Checks for equality between two svm_models.

      Equality is defined as bit-wise exact for SV, rho, sv_coeff, probA and probB.

      Parameters:
      first - The first model.
      second - The second model.
      Returns:
      True if the models are identical.
    • serializeParameters

      protected static org.tribuo.common.libsvm.protos.SVMParameterProto serializeParameters(libsvm.svm_parameter param)
      Serializes a svm_parameter to a protobuf.
      Parameters:
      param - The parameters to serialize.
      Returns:
      The protobuf.
    • serializeModel

      protected static org.tribuo.common.libsvm.protos.SVMModelProto serializeModel(libsvm.svm_model model)
      Serializes a LibSVM svm_model to a protobuf.
      Parameters:
      model - The model to serialize.
      Returns:
      The protobuf representation.
    • deserializeParameters

      protected static libsvm.svm_parameter deserializeParameters(org.tribuo.common.libsvm.protos.SVMParameterProto proto)
      Deserializes svm_parameter from a protobuf.
      Parameters:
      proto - The protobuf to deserialize.
      Returns:
      The parameters.
    • deserializeModel

      protected static libsvm.svm_model deserializeModel(org.tribuo.common.libsvm.protos.SVMModelProto proto)
      Deserializes a LibSVM svm_model from a protobuf.
      Parameters:
      proto - The protobuf to deserialize.
      Returns:
      The svm_model.